Skip to content

Commit aacc321

Browse files
committed
CT Bone operator updated with clcat pypi package
1 parent 24eb93b commit aacc321

File tree

4 files changed

+15
-39
lines changed

4 files changed

+15
-39
lines changed

examples/apps/ct_bone_seg_app/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
_current_dir = os.path.abspath(os.path.dirname(__file__))
55
if sys.path and os.path.abspath(sys.path[0]) != _current_dir:
66
sys.path.insert(0, _current_dir)
7-
#lib_path = os.path.join(_current_dir, "lib/")
8-
#sys.path.insert(0, lib_path)
7+
98
del _current_dir

examples/apps/ct_bone_seg_app/app.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 MONAI Consortium
1+
# Copyright 2022 MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -14,24 +14,16 @@
1414
from monai.deploy.core import Application, env, resource
1515

1616
@resource(cpu=1, gpu=1)
17-
# pip_packages can be a string that is a path(str) to requirements.txt file or a list of packages.
18-
#@env(pip_packages=["scikit-image >= 0.17.2"])
1917
class App(Application):
2018
"""This is a CT Bone application.
2119
"""
2220

23-
# App's name. <class name>('App') if not specified.
2421
name = "ct_bone_app"
25-
# App's description. <class docstring> if not specified.
2622
description = "CT Bone segmentation app."
27-
# App's version. <git version tag> or '0.0.0' if not specified.
2823
version = "0.1.0"
2924

3025
def compose(self):
3126
"""This application has two operators.
32-
33-
Each operator has a single input and a single output port.
34-
Each operator performs some kind of image processing function.
3527
"""
3628

3729
dcm_to_mhd = DicomToMhd()

examples/apps/ct_bone_seg_app/ct_bone_operator.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 MONAI Consortium
1+
# Copyright 2022 MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -11,20 +11,13 @@
1111

1212
import monai.deploy.core as md
1313
from monai.deploy.core import DataPath, ExecutionContext, Image, InputContext, IOType, Operator, OutputContext
14-
import sys, os
15-
16-
lib_path = "/usr/local/lib"
17-
sys.path.append(lib_path)
18-
import clinical_algos as calg
19-
14+
import os
2015

2116
@md.input("image", DataPath, IOType.DISK)
2217
@md.output("image", DataPath, IOType.DISK)
23-
# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other
24-
# operators and the application in packaging time.
25-
# @md.env(pip_packages=["scikit-image >= 0.17.2"])
18+
@md.env(pip_packages=["patchelf", "clcat"])
2619
class CtBoneOperator(Operator):
27-
"""This Operator implements a CT Bone segmentation
20+
"""This Operator implements CT Bone segmentation
2821
"""
2922

3023
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
3629
inputfile = os.path.join(input_path, "intermediate_mhd_data.mhd")
3730
elif input_path.is_file():
3831
inputfile = str(input_path)
39-
40-
print(inputfile)
32+
else:
33+
raise("Input path invalid from input context")
4134

4235
output_path = op_output.get().path
4336
output_path.mkdir(parents=True, exist_ok=True)
4437
outputfile = os.path.join(output_path, "bone_mask.mhd")
45-
print(outputfile)
46-
47-
print("Entering Clara CAT Algorithms")
4838

49-
status = calg.ct_bone(inputfile, outputfile)
39+
import clcat.ct_algos as cact
40+
status = cact.ct_bone(inputfile, outputfile)
5041

5142
if input_path.is_dir():
5243
os.remove(inputfile)

examples/apps/ct_bone_seg_app/dicom_to_mhd.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 MONAI Consortium
1+
# Copyright 2022 MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -16,8 +16,6 @@
1616

1717
@md.input("image", DataPath, IOType.DISK)
1818
@md.output("image", DataPath, IOType.DISK)
19-
# If `pip_packages` is specified, the definition will be aggregated with the package dependency list of other
20-
# operators and the application in packaging time.
2119
@md.env(pip_packages=["SimpleITK==1.2.4"])
2220
class DicomToMhd(Operator):
2321
"""
@@ -29,12 +27,9 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe
2927

3028
input_path = op_input.get().path
3129
if input_path.is_dir():
32-
print(input_path)
33-
_current_dir = os.path.abspath(os.path.dirname(__file__))
34-
op_output.set(DataPath(_current_dir))
30+
current_file_dir = os.path.abspath(os.path.dirname(__file__))
31+
op_output.set(DataPath(current_file_dir))
3532
output_path = op_output.get().path
36-
if output_path.is_dir():
37-
print(output_path)
3833

3934
output_file_path = os.path.join(output_path, "intermediate_mhd_data.mhd")
4035

@@ -45,12 +40,11 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe
4540
fixed = reader.Execute()
4641
sitk.WriteImage(fixed, output_file_path)
4742
else:
48-
print("Input path is not a directory")
4943
if os.path.isfile(input_path):
5044
extension = os.path.splitext(input_path)[1]
5145
if extension == '.mhd':
52-
print("Input path is a MHD file")
53-
print("Setting output folder as input folder")
46+
# Input path is a MHD file
47+
# Setting output folder as input folder
5448
op_output.set(DataPath(input_path))
5549
else:
5650
raise IOError('Unsupported extension')

0 commit comments

Comments
 (0)