From 739b9b8b1272bc0a3ee8494bf47686ffd58d47b1 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 16 Feb 2022 10:48:26 -0800 Subject: [PATCH 01/10] first version ct bone app Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/__init__.py | 9 +++ examples/apps/ct_bone_seg_app/__main__.py | 4 ++ examples/apps/ct_bone_seg_app/app.py | 43 +++++++++++++ .../apps/ct_bone_seg_app/ct_bone_operator.py | 57 +++++++++++++++++ examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 61 +++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 examples/apps/ct_bone_seg_app/__init__.py create mode 100644 examples/apps/ct_bone_seg_app/__main__.py create mode 100644 examples/apps/ct_bone_seg_app/app.py create mode 100644 examples/apps/ct_bone_seg_app/ct_bone_operator.py create mode 100644 examples/apps/ct_bone_seg_app/dicom_to_mhd.py diff --git a/examples/apps/ct_bone_seg_app/__init__.py b/examples/apps/ct_bone_seg_app/__init__.py new file mode 100644 index 00000000..e5dd2fa7 --- /dev/null +++ b/examples/apps/ct_bone_seg_app/__init__.py @@ -0,0 +1,9 @@ +import os +import sys + +_current_dir = os.path.abspath(os.path.dirname(__file__)) +if sys.path and os.path.abspath(sys.path[0]) != _current_dir: + sys.path.insert(0, _current_dir) + #lib_path = os.path.join(_current_dir, "lib/") + #sys.path.insert(0, lib_path) +del _current_dir \ No newline at end of file diff --git a/examples/apps/ct_bone_seg_app/__main__.py b/examples/apps/ct_bone_seg_app/__main__.py new file mode 100644 index 00000000..1581d095 --- /dev/null +++ b/examples/apps/ct_bone_seg_app/__main__.py @@ -0,0 +1,4 @@ +from app import App + +if __name__ == "__main__": + App(do_run=True) \ No newline at end of file diff --git a/examples/apps/ct_bone_seg_app/app.py b/examples/apps/ct_bone_seg_app/app.py new file mode 100644 index 00000000..1ac8a441 --- /dev/null +++ b/examples/apps/ct_bone_seg_app/app.py @@ -0,0 +1,43 @@ +# Copyright 2021 MONAI Consortium +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ct_bone_operator import CtBoneOperator +from dicom_to_mhd import DicomToMhd +from monai.deploy.core import Application, env, resource + +@resource(cpu=1, gpu=1) +# pip_packages can be a string that is a path(str) to requirements.txt file or a list of packages. +#@env(pip_packages=["scikit-image >= 0.17.2"]) +class App(Application): + """This is a CT Bone application. + """ + + # App's name. ('App') if not specified. + name = "ct_bone_app" + # App's description. if not specified. + description = "CT Bone segmentation app." + # App's version. or '0.0.0' if not specified. + version = "0.1.0" + + def compose(self): + """This application has two operators. + + Each operator has a single input and a single output port. + Each operator performs some kind of image processing function. + """ + + dcm_to_mhd = DicomToMhd() + bone_op = CtBoneOperator() + + self.add_flow(dcm_to_mhd, bone_op) + +if __name__ == "__main__": + App(do_run=True) diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py new file mode 100644 index 00000000..005d3544 --- /dev/null +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -0,0 +1,57 @@ +# Copyright 2021 MONAI Consortium +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import monai.deploy.core as md +from monai.deploy.core import DataPath, ExecutionContext, Image, InputContext, IOType, Operator, OutputContext +import sys, os + +lib_path = "/usr/local/lib" +sys.path.append(lib_path) +import clinical_algos as calg + + +@md.input("image", DataPath, IOType.DISK) +@md.output("image", DataPath, IOType.DISK) +# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other +# operators and the application in packaging time. +# @md.env(pip_packages=["scikit-image >= 0.17.2"]) +class CtBoneOperator(Operator): + """This Operator implements a CT Bone segmentation + """ + + def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext): + + input_path = op_input.get().path + inputfile = "" + + if input_path.is_dir(): + inputfile = os.path.join(input_path, "intermediate_mhd_data.mhd") + elif input_path.is_file(): + inputfile = str(input_path) + + print(inputfile) + + output_path = op_output.get().path + output_path.mkdir(parents=True, exist_ok=True) + outputfile = os.path.join(output_path, "bone_mask.mhd") + print(outputfile) + + print("Entering Clara CAT Algorithms") + + status = calg.ct_bone(inputfile, outputfile) + + if input_path.is_dir(): + os.remove(inputfile) + inputrawfile = os.path.join(input_path, "intermediate_mhd_data.raw") + os.remove(inputrawfile) + + if status != 0: + raise("Bone segmentation failed") \ No newline at end of file diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py new file mode 100644 index 00000000..514e4539 --- /dev/null +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -0,0 +1,61 @@ +# Copyright 2021 MONAI Consortium +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import monai.deploy.core as md +from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext +import SimpleITK as sitk +import os + +@md.input("image", DataPath, IOType.DISK) +@md.output("image", DataPath, IOType.DISK) +# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other +# operators and the application in packaging time. +@md.env(pip_packages=["SimpleITK==1.2.4"]) +class DicomToMhd(Operator): + """ + If input is DICOM: This operator converts a dicom image to a mhd image + If input is MHD: This operator sets the output path to input path + """ + + def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext): + + input_path = op_input.get().path + if input_path.is_dir(): + print(input_path) + _current_dir = os.path.abspath(os.path.dirname(__file__)) + op_output.set(DataPath(_current_dir)) + output_path = op_output.get().path + if output_path.is_dir(): + print(output_path) + + output_file_path = os.path.join(output_path, "intermediate_mhd_data.mhd") + + reader = sitk.ImageSeriesReader() + dicom_names = reader.GetGDCMSeriesFileNames(str(input_path)) + reader.SetFileNames(dicom_names) + + fixed = reader.Execute() + sitk.WriteImage(fixed, output_file_path) + else: + print("Input path is not a directory") + if os.path.isfile(input_path): + extension = os.path.splitext(input_path)[1] + if extension == '.mhd': + print("Input path is a MHD file") + print("Setting output folder as input folder") + op_output.set(DataPath(input_path)) + else: + raise IOError('Unsupported extension') + else: + raise IOError('Invalid input path') + + + \ No newline at end of file From bf1fbc2d8d037546852b97bc91ed30b54b5ad63d Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 00:27:22 -0800 Subject: [PATCH 02/10] CT Bone operator updated with clcat pypi package Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/__init__.py | 3 +-- examples/apps/ct_bone_seg_app/app.py | 10 +------- .../apps/ct_bone_seg_app/ct_bone_operator.py | 25 ++++++------------- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 16 ++++-------- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/__init__.py b/examples/apps/ct_bone_seg_app/__init__.py index e5dd2fa7..cdf11cff 100644 --- a/examples/apps/ct_bone_seg_app/__init__.py +++ b/examples/apps/ct_bone_seg_app/__init__.py @@ -4,6 +4,5 @@ _current_dir = os.path.abspath(os.path.dirname(__file__)) if sys.path and os.path.abspath(sys.path[0]) != _current_dir: sys.path.insert(0, _current_dir) - #lib_path = os.path.join(_current_dir, "lib/") - #sys.path.insert(0, lib_path) + del _current_dir \ No newline at end of file diff --git a/examples/apps/ct_bone_seg_app/app.py b/examples/apps/ct_bone_seg_app/app.py index 1ac8a441..0d6cfcbf 100644 --- a/examples/apps/ct_bone_seg_app/app.py +++ b/examples/apps/ct_bone_seg_app/app.py @@ -1,4 +1,4 @@ -# Copyright 2021 MONAI Consortium +# Copyright 2022 MONAI Consortium # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,24 +14,16 @@ from monai.deploy.core import Application, env, resource @resource(cpu=1, gpu=1) -# pip_packages can be a string that is a path(str) to requirements.txt file or a list of packages. -#@env(pip_packages=["scikit-image >= 0.17.2"]) class App(Application): """This is a CT Bone application. """ - # App's name. ('App') if not specified. name = "ct_bone_app" - # App's description. if not specified. description = "CT Bone segmentation app." - # App's version. or '0.0.0' if not specified. version = "0.1.0" def compose(self): """This application has two operators. - - Each operator has a single input and a single output port. - Each operator performs some kind of image processing function. """ dcm_to_mhd = DicomToMhd() diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py index 005d3544..44804c56 100644 --- a/examples/apps/ct_bone_seg_app/ct_bone_operator.py +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -1,4 +1,4 @@ -# Copyright 2021 MONAI Consortium +# Copyright 2022 MONAI Consortium # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -11,20 +11,13 @@ import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, Image, InputContext, IOType, Operator, OutputContext -import sys, os - -lib_path = "/usr/local/lib" -sys.path.append(lib_path) -import clinical_algos as calg - +import os @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) -# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other -# operators and the application in packaging time. -# @md.env(pip_packages=["scikit-image >= 0.17.2"]) +@md.env(pip_packages=["patchelf", "clcat"]) class CtBoneOperator(Operator): - """This Operator implements a CT Bone segmentation + """This Operator implements CT Bone segmentation """ def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext): @@ -36,17 +29,15 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe inputfile = os.path.join(input_path, "intermediate_mhd_data.mhd") elif input_path.is_file(): inputfile = str(input_path) - - print(inputfile) + else: + raise("Input path invalid from input context") output_path = op_output.get().path output_path.mkdir(parents=True, exist_ok=True) outputfile = os.path.join(output_path, "bone_mask.mhd") - print(outputfile) - - print("Entering Clara CAT Algorithms") - status = calg.ct_bone(inputfile, outputfile) + import clcat.ct_algos as cact + status = cact.ct_bone(inputfile, outputfile) if input_path.is_dir(): os.remove(inputfile) diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index 514e4539..cc3a68b1 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -1,4 +1,4 @@ -# Copyright 2021 MONAI Consortium +# Copyright 2022 MONAI Consortium # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,8 +16,6 @@ @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) -# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other -# operators and the application in packaging time. @md.env(pip_packages=["SimpleITK==1.2.4"]) class DicomToMhd(Operator): """ @@ -29,12 +27,9 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe input_path = op_input.get().path if input_path.is_dir(): - print(input_path) - _current_dir = os.path.abspath(os.path.dirname(__file__)) - op_output.set(DataPath(_current_dir)) + current_file_dir = os.path.abspath(os.path.dirname(__file__)) + op_output.set(DataPath(current_file_dir)) output_path = op_output.get().path - if output_path.is_dir(): - print(output_path) output_file_path = os.path.join(output_path, "intermediate_mhd_data.mhd") @@ -45,12 +40,11 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe fixed = reader.Execute() sitk.WriteImage(fixed, output_file_path) else: - print("Input path is not a directory") if os.path.isfile(input_path): extension = os.path.splitext(input_path)[1] if extension == '.mhd': - print("Input path is a MHD file") - print("Setting output folder as input folder") + # Input path is a MHD file + # Setting output folder as input folder op_output.set(DataPath(input_path)) else: raise IOError('Unsupported extension') From bb0efbee95398955e9f230076ed26c7b82d49ec2 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 00:30:55 -0800 Subject: [PATCH 03/10] end of line correction Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/__init__.py | 2 +- examples/apps/ct_bone_seg_app/ct_bone_operator.py | 2 +- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/__init__.py b/examples/apps/ct_bone_seg_app/__init__.py index cdf11cff..c8f6f0d1 100644 --- a/examples/apps/ct_bone_seg_app/__init__.py +++ b/examples/apps/ct_bone_seg_app/__init__.py @@ -5,4 +5,4 @@ if sys.path and os.path.abspath(sys.path[0]) != _current_dir: sys.path.insert(0, _current_dir) -del _current_dir \ No newline at end of file +del _current_dir diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py index 44804c56..d777162d 100644 --- a/examples/apps/ct_bone_seg_app/ct_bone_operator.py +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -45,4 +45,4 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe os.remove(inputrawfile) if status != 0: - raise("Bone segmentation failed") \ No newline at end of file + raise("Bone segmentation failed") diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index cc3a68b1..59d191fe 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -50,6 +50,3 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe raise IOError('Unsupported extension') else: raise IOError('Invalid input path') - - - \ No newline at end of file From 71669134ea6c843f5e7cc894932d72078eb14231 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 00:32:05 -0800 Subject: [PATCH 04/10] end of line correction Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/apps/ct_bone_seg_app/__main__.py b/examples/apps/ct_bone_seg_app/__main__.py index 1581d095..412a8ca1 100644 --- a/examples/apps/ct_bone_seg_app/__main__.py +++ b/examples/apps/ct_bone_seg_app/__main__.py @@ -1,4 +1,4 @@ from app import App if __name__ == "__main__": - App(do_run=True) \ No newline at end of file + App(do_run=True) From e9847f0a0e8e545711c417f7d4f6a78403f5be98 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 00:44:08 -0800 Subject: [PATCH 05/10] isort check Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/app.py | 4 +++- examples/apps/ct_bone_seg_app/ct_bone_operator.py | 4 +++- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/app.py b/examples/apps/ct_bone_seg_app/app.py index 0d6cfcbf..37bdbb54 100644 --- a/examples/apps/ct_bone_seg_app/app.py +++ b/examples/apps/ct_bone_seg_app/app.py @@ -11,7 +11,9 @@ from ct_bone_operator import CtBoneOperator from dicom_to_mhd import DicomToMhd -from monai.deploy.core import Application, env, resource + +from monai.deploy.core import Application, resource + @resource(cpu=1, gpu=1) class App(Application): diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py index d777162d..774e6e57 100644 --- a/examples/apps/ct_bone_seg_app/ct_bone_operator.py +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -9,9 +9,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, Image, InputContext, IOType, Operator, OutputContext -import os + @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index 59d191fe..6f44bbf7 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -9,10 +9,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os + +import SimpleITK as sitk + import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext -import SimpleITK as sitk -import os + @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) From a6e828d8ccb1de43f37e2c5019af520607b32e35 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 10:46:11 -0800 Subject: [PATCH 06/10] fixing formatting issues Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/app.py | 11 +++++------ .../apps/ct_bone_seg_app/ct_bone_operator.py | 18 +++++++++--------- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/app.py b/examples/apps/ct_bone_seg_app/app.py index 37bdbb54..fe63bfa1 100644 --- a/examples/apps/ct_bone_seg_app/app.py +++ b/examples/apps/ct_bone_seg_app/app.py @@ -17,21 +17,20 @@ @resource(cpu=1, gpu=1) class App(Application): - """This is a CT Bone application. - """ + """This is a CT Bone application.""" name = "ct_bone_app" description = "CT Bone segmentation app." version = "0.1.0" def compose(self): - """This application has two operators. - """ - + """This application has two operators.""" + dcm_to_mhd = DicomToMhd() bone_op = CtBoneOperator() - + self.add_flow(dcm_to_mhd, bone_op) + if __name__ == "__main__": App(do_run=True) diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py index 774e6e57..c1cf43f6 100644 --- a/examples/apps/ct_bone_seg_app/ct_bone_operator.py +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -19,32 +19,32 @@ @md.output("image", DataPath, IOType.DISK) @md.env(pip_packages=["patchelf", "clcat"]) class CtBoneOperator(Operator): - """This Operator implements CT Bone segmentation - """ + """This Operator implements CT Bone segmentation""" def compute(self, op_input: InputContext, op_output: OutputContext, context: ExecutionContext): - + input_path = op_input.get().path inputfile = "" - + if input_path.is_dir(): inputfile = os.path.join(input_path, "intermediate_mhd_data.mhd") elif input_path.is_file(): inputfile = str(input_path) else: - raise("Input path invalid from input context") + raise ("Input path invalid from input context") output_path = op_output.get().path output_path.mkdir(parents=True, exist_ok=True) outputfile = os.path.join(output_path, "bone_mask.mhd") - + import clcat.ct_algos as cact + status = cact.ct_bone(inputfile, outputfile) - + if input_path.is_dir(): os.remove(inputfile) - inputrawfile = os.path.join(input_path, "intermediate_mhd_data.raw") + inputrawfile = os.path.join(input_path, "intermediate_mhd_data.raw") os.remove(inputrawfile) if status != 0: - raise("Bone segmentation failed") + raise ("Bone segmentation failed") diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index 6f44bbf7..bfa7d302 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -33,7 +33,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe current_file_dir = os.path.abspath(os.path.dirname(__file__)) op_output.set(DataPath(current_file_dir)) output_path = op_output.get().path - + output_file_path = os.path.join(output_path, "intermediate_mhd_data.mhd") reader = sitk.ImageSeriesReader() @@ -45,11 +45,11 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe else: if os.path.isfile(input_path): extension = os.path.splitext(input_path)[1] - if extension == '.mhd': + if extension == ".mhd": # Input path is a MHD file # Setting output folder as input folder op_output.set(DataPath(input_path)) else: - raise IOError('Unsupported extension') + raise IOError("Unsupported extension") else: - raise IOError('Invalid input path') + raise IOError("Invalid input path") From 60a1e27cb1454003e946e102cd0bb6ac5565b137 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 11:03:30 -0800 Subject: [PATCH 07/10] styling issues fixed related to flake8 Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/ct_bone_operator.py | 6 +++--- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/ct_bone_operator.py b/examples/apps/ct_bone_seg_app/ct_bone_operator.py index c1cf43f6..62b168d2 100644 --- a/examples/apps/ct_bone_seg_app/ct_bone_operator.py +++ b/examples/apps/ct_bone_seg_app/ct_bone_operator.py @@ -12,7 +12,7 @@ import os import monai.deploy.core as md -from monai.deploy.core import DataPath, ExecutionContext, Image, InputContext, IOType, Operator, OutputContext +from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext @md.input("image", DataPath, IOType.DISK) @@ -31,7 +31,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe elif input_path.is_file(): inputfile = str(input_path) else: - raise ("Input path invalid from input context") + raise IOError("Input path invalid from input context") output_path = op_output.get().path output_path.mkdir(parents=True, exist_ok=True) @@ -47,4 +47,4 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe os.remove(inputrawfile) if status != 0: - raise ("Bone segmentation failed") + raise Exception("Bone segmentation failed") diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index bfa7d302..80add89d 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -11,7 +11,7 @@ import os -import SimpleITK as sitk +import SimpleITK as SITK import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext @@ -36,12 +36,12 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe output_file_path = os.path.join(output_path, "intermediate_mhd_data.mhd") - reader = sitk.ImageSeriesReader() + reader = SITK.ImageSeriesReader() dicom_names = reader.GetGDCMSeriesFileNames(str(input_path)) reader.SetFileNames(dicom_names) fixed = reader.Execute() - sitk.WriteImage(fixed, output_file_path) + SITK.WriteImage(fixed, output_file_path) else: if os.path.isfile(input_path): extension = os.path.splitext(input_path)[1] From 3744506a8339e07774bbdb54c33faf2dc2181671 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 20:27:16 -0800 Subject: [PATCH 08/10] flake8 fix for ctboneseg Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index 80add89d..41eca641 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -11,12 +11,9 @@ import os -import SimpleITK as SITK - import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext - @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) @md.env(pip_packages=["SimpleITK==1.2.4"]) @@ -30,6 +27,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe input_path = op_input.get().path if input_path.is_dir(): + import SimpleITK as SITK current_file_dir = os.path.abspath(os.path.dirname(__file__)) op_output.set(DataPath(current_file_dir)) output_path = op_output.get().path From 4b65fcd7592e792ce8b80400711347d0ba9b42f4 Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 20:31:34 -0800 Subject: [PATCH 09/10] isort fix for dicome_to_mhd Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index 41eca641..e4dbd475 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -14,6 +14,7 @@ import monai.deploy.core as md from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext + @md.input("image", DataPath, IOType.DISK) @md.output("image", DataPath, IOType.DISK) @md.env(pip_packages=["SimpleITK==1.2.4"]) From 75e7b4a03e9dab1dcab23a31b7e8705b568905ab Mon Sep 17 00:00:00 2001 From: Shekhar Dwivedi Date: Wed, 23 Feb 2022 20:41:39 -0800 Subject: [PATCH 10/10] black fix for dicome_to_mhd Signed-off-by: Shekhar Dwivedi --- examples/apps/ct_bone_seg_app/dicom_to_mhd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py index e4dbd475..1f38143f 100644 --- a/examples/apps/ct_bone_seg_app/dicom_to_mhd.py +++ b/examples/apps/ct_bone_seg_app/dicom_to_mhd.py @@ -29,6 +29,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe input_path = op_input.get().path if input_path.is_dir(): import SimpleITK as SITK + current_file_dir = os.path.abspath(os.path.dirname(__file__)) op_output.set(DataPath(current_file_dir)) output_path = op_output.get().path