-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compare-images): add vector-magnitude computation
- Loading branch information
Showing
13 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...es/python/itkwasm-compare-images-emscripten/itkwasm_compare_images_emscripten/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""itkwasm-compare-images-emscripten: Read files and images related to compare-images file format. Emscripten implementation.""" | ||
|
||
from .compare_double_images_async import compare_double_images_async | ||
from .vector_magnitude_async import vector_magnitude_async | ||
|
||
from ._version import __version__ |
2 changes: 1 addition & 1 deletion
2
...ompare-images-emscripten/itkwasm_compare_images_emscripten/compare_double_images_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...asm-compare-images-emscripten/itkwasm_compare_images_emscripten/vector_magnitude_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
# Generated file. Do not edit. | ||
|
||
from pathlib import Path | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from .js_package import js_package | ||
|
||
from itkwasm.pyodide import ( | ||
to_js, | ||
to_py, | ||
js_resources | ||
) | ||
from itkwasm import ( | ||
InterfaceTypes, | ||
Image, | ||
) | ||
|
||
async def vector_magnitude_async( | ||
vector_image: Image, | ||
) -> Image: | ||
"""Generate a scalar magnitude image based on the input vector's norm. | ||
:param vector_image: Input vector image | ||
:type vector_image: Image | ||
:return: Output magnitude image | ||
:rtype: Image | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
|
||
outputs = await js_module.vectorMagnitude(web_worker, to_js(vector_image), **kwargs) | ||
|
||
output_web_worker = None | ||
output_list = [] | ||
outputs_object_map = outputs.as_object_map() | ||
for output_name in outputs.object_keys(): | ||
if output_name == 'webWorker': | ||
output_web_worker = outputs_object_map[output_name] | ||
else: | ||
output_list.append(to_py(outputs_object_map[output_name])) | ||
|
||
js_resources.web_worker = output_web_worker | ||
|
||
if len(output_list) == 1: | ||
return output_list[0] | ||
return tuple(output_list) |
3 changes: 2 additions & 1 deletion
3
...compare-images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""itkwasm-compare-images-wasi: Read files and images related to compare-images file format. WASI implementation.""" | ||
|
||
from .compare_double_images import compare_double_images | ||
from .compare_images import compare_images | ||
from .compare_double_images import compare_double_images | ||
from .vector_magnitude import vector_magnitude | ||
|
||
from ._version import __version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...images/python/itkwasm-compare-images-wasi/itkwasm_compare_images_wasi/vector_magnitude.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
# Generated file. Do not edit. | ||
|
||
from pathlib import Path, PurePosixPath | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from importlib_resources import files as file_resources | ||
|
||
_pipeline = None | ||
|
||
from itkwasm import ( | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
Pipeline, | ||
Image, | ||
) | ||
|
||
def vector_magnitude( | ||
vector_image: Image, | ||
) -> Image: | ||
"""Generate a scalar magnitude image based on the input vector's norm. | ||
:param vector_image: Input vector image | ||
:type vector_image: Image | ||
:return: Output magnitude image | ||
:rtype: Image | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_compare_images_wasi').joinpath(Path('wasm_modules') / Path('vector-magnitude.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.Image), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
PipelineInput(InterfaceTypes.Image, vector_image), | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
args.append('0') | ||
# Outputs | ||
args.append('0') | ||
# Options | ||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = outputs[0].data | ||
return result | ||
|
Binary file modified
BIN
-7.7 MB
(16%)
...pare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/compare-double-images.wasi.wasm
Binary file not shown.
Binary file added
BIN
+1.37 MB
...m-compare-images-wasi/itkwasm_compare_images_wasi/wasm_modules/vector-magnitude.wasi.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...s/compare-images/python/itkwasm-compare-images/itkwasm_compare_images/vector_magnitude.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated file. Do not edit. | ||
|
||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from itkwasm import ( | ||
environment_dispatch, | ||
Image, | ||
) | ||
|
||
def vector_magnitude( | ||
vector_image: Image, | ||
) -> Image: | ||
"""Generate a scalar magnitude image based on the input vector's norm. | ||
:param vector_image: Input vector image | ||
:type vector_image: Image | ||
:return: Output magnitude image | ||
:rtype: Image | ||
""" | ||
func = environment_dispatch("itkwasm_compare_images", "vector_magnitude") | ||
output = func(vector_image) | ||
return output |
24 changes: 24 additions & 0 deletions
24
...are-images/python/itkwasm-compare-images/itkwasm_compare_images/vector_magnitude_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated file. Do not edit. | ||
|
||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from itkwasm import ( | ||
environment_dispatch, | ||
Image, | ||
) | ||
|
||
async def vector_magnitude_async( | ||
vector_image: Image, | ||
) -> Image: | ||
"""Generate a scalar magnitude image based on the input vector's norm. | ||
:param vector_image: Input vector image | ||
:type vector_image: Image | ||
:return: Output magnitude image | ||
:rtype: Image | ||
""" | ||
func = environment_dispatch("itkwasm_compare_images", "vector_magnitude_async") | ||
output = await func(vector_image) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters