diff --git a/packages/dicom/gdcm/CMakeLists.txt b/packages/dicom/gdcm/CMakeLists.txt index faa32f52b..1bde8dab4 100644 --- a/packages/dicom/gdcm/CMakeLists.txt +++ b/packages/dicom/gdcm/CMakeLists.txt @@ -10,6 +10,20 @@ include(${ITK_USE_FILE}) add_executable(read-image-dicom-file-series read-image-dicom-file-series.cxx) target_link_libraries(read-image-dicom-file-series PUBLIC ${ITK_LIBRARIES}) +add_executable(image-sets-normalization image-sets-normalization.cxx) +target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES}) + +enable_testing() + +add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help) + +add_test(NAME image-sets-normalization-smoke + COMMAND image-sets-normalization image-sets.json --files + ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm + ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm + ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm +) + if (WASI) return() endif() @@ -63,22 +77,6 @@ add_dependencies(${Iconv} ${Iconv_LIBRARY}) add_executable(read-dicom-tags read-dicom-tags.cxx) target_link_libraries(read-dicom-tags PUBLIC ${ITK_LIBRARIES} ${Iconv_LIBRARIES} ${Iconv}) - -add_executable(image-sets-normalization image-sets-normalization.cxx) -target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES}) - -enable_testing() - -add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help) - -add_test(NAME image-sets-normalization-smoke - COMMAND image-sets-normalization image-sets.json --files - ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm - ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm - ${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm -) - - if (EMSCRIPTEN) foreach(dicom_io_module read-image-dicom-file-series diff --git a/packages/dicom/python/itkwasm-dicom-emscripten/itkwasm_dicom_emscripten/image_sets_normalization_async.py b/packages/dicom/python/itkwasm-dicom-emscripten/itkwasm_dicom_emscripten/image_sets_normalization_async.py new file mode 100644 index 000000000..7157a1780 --- /dev/null +++ b/packages/dicom/python/itkwasm-dicom-emscripten/itkwasm_dicom_emscripten/image_sets_normalization_async.py @@ -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) diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/__init__.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/__init__.py index f36a5e54a..b084efeb0 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/__init__.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/__init__.py @@ -5,5 +5,6 @@ from .structured_report_to_html import structured_report_to_html from .structured_report_to_text import structured_report_to_text from .read_image_dicom_file_series import read_image_dicom_file_series +from .image_sets_normalization import image_sets_normalization from ._version import __version__ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/image_sets_normalization.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/image_sets_normalization.py new file mode 100644 index 000000000..198ee0a1c --- /dev/null +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/image_sets_normalization.py @@ -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 + diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm index 11312e72f..0eda6d6d2 100755 Binary files a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/apply-presentation-state-to-image.wasi.wasm differ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm new file mode 100755 index 000000000..5d98c69e4 Binary files /dev/null and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/image-sets-normalization.wasi.wasm differ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm index 3e7733865..9af005403 100755 Binary files a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm and b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/wasm_modules/read-image-dicom-file-series.wasi.wasm differ diff --git a/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py b/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py index 7edcce470..8b9dfc5e7 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/tests/test_image_sets_normalization.py @@ -1,10 +1,8 @@ -# Generated file. To retain edits, remove this comment. +from itkwasm_dicom_wasi import image_sets_normalization from .common import test_input_path, test_output_path -def test_sort_dicom_series(): - from itkwasm_dicom_wasi import image_sets_normalization - +def test_image_sets_normalization(): test_file_path = test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm" assert test_file_path.exists() diff --git a/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization.py b/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization.py new file mode 100644 index 000000000..4a63d0167 --- /dev/null +++ b/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization.py @@ -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 diff --git a/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization_async.py b/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization_async.py new file mode 100644 index 000000000..e6961968f --- /dev/null +++ b/packages/dicom/python/itkwasm-dicom/itkwasm_dicom/image_sets_normalization_async.py @@ -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