-
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.
Change CmakeLists to build image-sets-normalization for WASI.
Fix wasi/__init__ to expose image_sets_normalization.
- Loading branch information
Showing
10 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
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
...ython/itkwasm-dicom-emscripten/itkwasm_dicom_emscripten/image_sets_normalization_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. | ||
|
||
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, | ||
BinaryFile, | ||
) | ||
|
||
async def image_sets_normalization_async( | ||
files: List[os.PathLike] = [], | ||
) -> Any: | ||
"""Group DICOM files into image sets | ||
:param files: DICOM files | ||
:type files: os.PathLike | ||
:return: Image sets JSON | ||
:rtype: Any | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if files is not None: | ||
kwargs["files"] = to_js(BinaryFile(files)) | ||
|
||
outputs = await js_module.imageSetsNormalization(webWorker=web_worker, noCopy=True, **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) |
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
63 changes: 63 additions & 0 deletions
63
packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/image_sets_normalization.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,63 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
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, | ||
BinaryFile, | ||
) | ||
|
||
def image_sets_normalization( | ||
files: List[os.PathLike] = [], | ||
) -> Any: | ||
"""Group DICOM files into image sets | ||
:param files: DICOM files | ||
:type files: os.PathLike | ||
:return: Image sets JSON | ||
:rtype: Any | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('image-sets-normalization.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.JsonCompatible), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
# Outputs | ||
image_sets_metadata_name = '0' | ||
args.append(image_sets_metadata_name) | ||
|
||
# Options | ||
input_count = len(pipeline_inputs) | ||
if len(files) < 1: | ||
raise ValueError('"files" kwarg must have a length > 1') | ||
if len(files) > 0: | ||
args.append('--files') | ||
for value in files: | ||
input_file = str(PurePosixPath(value)) | ||
pipeline_inputs.append(PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(value))) | ||
args.append(input_file) | ||
|
||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = outputs[0].data | ||
return result | ||
|
Binary file modified
BIN
-204 Bytes
(100%)
...sm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm
Binary file not shown.
Binary file added
BIN
+610 KB
...hon/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm
Binary file not shown.
Binary file modified
BIN
-8.36 KB
(100%)
...itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm
Binary file not shown.
6 changes: 2 additions & 4 deletions
6
packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.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
24 changes: 24 additions & 0 deletions
24
packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization.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, | ||
BinaryFile, | ||
) | ||
|
||
def image_sets_normalization( | ||
files: List[os.PathLike] = [], | ||
) -> Any: | ||
"""Group DICOM files into image sets | ||
:param files: DICOM files | ||
:type files: os.PathLike | ||
:return: Image sets JSON | ||
:rtype: Any | ||
""" | ||
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization") | ||
output = func(files=files) | ||
return output |
24 changes: 24 additions & 0 deletions
24
packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization_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, | ||
BinaryFile, | ||
) | ||
|
||
async def image_sets_normalization_async( | ||
files: List[os.PathLike] = [], | ||
) -> Any: | ||
"""Group DICOM files into image sets | ||
:param files: DICOM files | ||
:type files: os.PathLike | ||
:return: Image sets JSON | ||
:rtype: Any | ||
""" | ||
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization_async") | ||
output = await func(files=files) | ||
return output |