Skip to content

Commit b0ad0ee

Browse files
committed
Fix DICOM attribute handling
Existing implementation did not set attributes in advance, and their availability are checked by handing AttributeError. For the reason, initializing those attributes with None caused spleen app execution failure. (All metadata dictionary in Domain class is filled with None even for non-available attributes) With this patch, the attribute's availability is checked by checking if its value is None and getters return None if attributes are not set (using getattr() method). Signed-off-by: Gigon Bae <[email protected]>
1 parent c65066c commit b0ad0ee

File tree

4 files changed

+90
-141
lines changed

4 files changed

+90
-141
lines changed

examples/apps/ai_spleen_seg_app/spleen_seg_operator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import logging
1313

1414
from monai.deploy.core import ExecutionContext, Image, InputContext, IOType, Operator, OutputContext, env, input, output
15-
1615
from monai.deploy.operators.monai_seg_inference_operator import InMemImageReader, MonaiSegInferenceOperator
1716
from monai.transforms import (
1817
Activationsd,

monai/deploy/core/domain/dicom_series.py

Lines changed: 48 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12-
from typing import Any
13-
1412
from .dicom_sop_instance import DICOMSOPInstance
1513
from .domain import Domain
1614

@@ -23,22 +21,24 @@ def __init__(self, series_instance_uid):
2321
self._series_instance_uid = series_instance_uid
2422
self._sop_instances = []
2523

26-
self._series_date: Any = None
27-
self._series_time: Any = None
28-
self._modality: Any = None
29-
self._series_description: Any = None
30-
self._body_part_examined: Any = None
31-
self._patient_position: Any = None
32-
self._series_number: Any = None
33-
self._laterality: Any = None
34-
self._row_pixel_spacing: Any = None
35-
self._col_pixel_spacing: Any = None
36-
self._depth_pixel_spacing: Any = None
37-
self._row_direction_cosine: Any = None
38-
self._col_direction_cosine: Any = None
39-
self._depth_direction_cosine: Any = None
40-
self._dicom_affine_transform: Any = None
41-
self._nifti_affine_transform: Any = None
24+
# Do not set attributes in advance to save memory
25+
26+
# self._series_date: Any = None
27+
# self._series_time: Any = None
28+
# self._modality: Any = None
29+
# self._series_description: Any = None
30+
# self._body_part_examined: Any = None
31+
# self._patient_position: Any = None
32+
# self._series_number: Any = None
33+
# self._laterality: Any = None
34+
# self._row_pixel_spacing: Any = None
35+
# self._col_pixel_spacing: Any = None
36+
# self._depth_pixel_spacing: Any = None
37+
# self._row_direction_cosine: Any = None
38+
# self._col_direction_cosine: Any = None
39+
# self._depth_direction_cosine: Any = None
40+
# self._dicom_affine_transform: Any = None
41+
# self._nifti_affine_transform: Any = None
4242

4343
def get_series_instance_uid(self):
4444
return self._series_instance_uid
@@ -52,127 +52,127 @@ def get_sop_instances(self):
5252

5353
@property
5454
def series_date(self):
55-
return self._series_date
55+
return getattr(self, "_series_date", None)
5656

5757
@series_date.setter
5858
def series_date(self, val):
5959
self._series_date = val
6060

6161
@property
6262
def series_time(self):
63-
return self._series_time
63+
return getattr(self, "_series_time", None)
6464

6565
@series_time.setter
6666
def series_time(self, val):
6767
self._series_time = val
6868

6969
@property
7070
def modality(self):
71-
return self._modality
71+
return getattr(self, "_modality", None)
7272

7373
@modality.setter
7474
def modality(self, val):
7575
self._modality = val
7676

7777
@property
7878
def series_description(self):
79-
return self._series_description
79+
return getattr(self, "_series_description", None)
8080

8181
@series_description.setter
8282
def series_description(self, val):
8383
self._series_description = val
8484

8585
@property
8686
def body_part_examined(self):
87-
return self._body_part_examined
87+
return getattr(self, "_body_part_examined", None)
8888

8989
@body_part_examined.setter
9090
def body_part_examined(self, val):
9191
self._body_part_examined = val
9292

9393
@property
9494
def patient_position(self):
95-
return self._patient_position
95+
return getattr(self, "_patient_position", None)
9696

9797
@patient_position.setter
9898
def patient_position(self, val):
9999
self._patient_position = val
100100

101101
@property
102102
def series_number(self):
103-
return self._series_number
103+
return getattr(self, "_series_number", None)
104104

105105
@series_number.setter
106106
def series_number(self, val):
107107
self._series_number = val
108108

109109
@property
110110
def laterality(self):
111-
return self._laterality
111+
return getattr(self, "_laterality", None)
112112

113113
@laterality.setter
114114
def laterality(self, val):
115115
self._laterality = val
116116

117117
@property
118118
def row_pixel_spacing(self):
119-
return self._row_pixel_spacing
119+
return getattr(self, "_row_pixel_spacing", None)
120120

121121
@row_pixel_spacing.setter
122122
def row_pixel_spacing(self, val):
123123
self._row_pixel_spacing = val
124124

125125
@property
126126
def col_pixel_spacing(self):
127-
return self._col_pixel_spacing
127+
return getattr(self, "_col_pixel_spacing", None)
128128

129129
@col_pixel_spacing.setter
130130
def col_pixel_spacing(self, val):
131131
self._col_pixel_spacing = val
132132

133133
@property
134134
def depth_pixel_spacing(self):
135-
return self._depth_pixel_spacing
135+
return getattr(self, "_depth_pixel_spacing", None)
136136

137137
@depth_pixel_spacing.setter
138138
def depth_pixel_spacing(self, val):
139139
self._depth_pixel_spacing = val
140140

141141
@property
142142
def row_direction_cosine(self):
143-
return self._row_direction_cosine
143+
return getattr(self, "_row_direction_cosine", None)
144144

145145
@row_direction_cosine.setter
146146
def row_direction_cosine(self, val):
147147
self._row_direction_cosine = val
148148

149149
@property
150150
def col_direction_cosine(self):
151-
return self._col_direction_cosine
151+
return getattr(self, "_col_direction_cosine", None)
152152

153153
@col_direction_cosine.setter
154154
def col_direction_cosine(self, val):
155155
self._col_direction_cosine = val
156156

157157
@property
158158
def depth_direction_cosine(self):
159-
return self._depth_direction_cosine
159+
return getattr(self, "_depth_direction_cosine", None)
160160

161161
@depth_direction_cosine.setter
162162
def depth_direction_cosine(self, val):
163163
self._depth_direction_cosine = val
164164

165165
@property
166166
def dicom_affine_transform(self):
167-
return self._dicom_affine_transform
167+
return getattr(self, "_dicom_affine_transform", None)
168168

169169
@dicom_affine_transform.setter
170170
def dicom_affine_transform(self, val):
171171
self._dicom_affine_transform = val
172172

173173
@property
174174
def nifti_affine_transform(self):
175-
return self._nifti_affine_transform
175+
return getattr(self, "_nifti_affine_transform", None)
176176

177177
@nifti_affine_transform.setter
178178
def nifti_affine_transform(self, val):
@@ -184,83 +184,56 @@ def __str__(self):
184184
series_instance_uid_attr = "Series Instance UID: " + self._series_instance_uid + "\n"
185185
result += series_instance_uid_attr
186186

187-
try:
188-
num_sop_instances = "Num SOP Instances: " + str(len(self._sop_instances)) + "\n"
189-
result += num_sop_instances
190-
except AttributeError:
191-
pass
187+
num_sop_instances = "Num SOP Instances: " + str(len(self._sop_instances)) + "\n"
188+
result += num_sop_instances
192189

193-
try:
190+
if self.series_date is not None:
194191
series_date_attr = "Series Date: " + self.series_date + "\n"
195192
result += series_date_attr
196-
except AttributeError:
197-
pass
198193

199-
try:
194+
if self.series_time is not None:
200195
series_time_attr = "Series Time: " + self.series_time + "\n"
201196
result += series_time_attr
202-
except AttributeError:
203-
pass
204197

205-
try:
198+
if self.modality is not None:
206199
modality_attr = "Modality: " + self.modality + "\n"
207200
result += modality_attr
208-
except AttributeError:
209-
pass
210201

211-
try:
202+
if self.series_description is not None:
212203
series_desc_attr = "Series Description: " + self.series_description + "\n"
213204
result += series_desc_attr
214-
except AttributeError:
215-
pass
216205

217-
try:
206+
if self.row_pixel_spacing is not None:
218207
row_pixel_spacing_attr = "Row Pixel Spacing: " + str(self.row_pixel_spacing) + "\n"
219208
result += row_pixel_spacing_attr
220-
except AttributeError:
221-
pass
222209

223-
try:
210+
if self.col_pixel_spacing is not None:
224211
col_pixel_spacing_attr = "Column Pixel Spacing: " + str(self.col_pixel_spacing) + "\n"
225212
result += col_pixel_spacing_attr
226-
except AttributeError:
227-
pass
228213

229-
try:
214+
if self.depth_pixel_spacing is not None:
230215
depth_pixel_spacing_attr = "Depth Pixel Spacing: " + str(self.depth_pixel_spacing) + "\n"
231216
result += depth_pixel_spacing_attr
232-
except AttributeError:
233-
pass
234217

235-
try:
218+
if self.row_direction_cosine is not None:
236219
row_direction_cosine_attr = "Row Direction Cosine: " + str(self.row_direction_cosine) + "\n"
237220
result += row_direction_cosine_attr
238-
except AttributeError:
239-
pass
240221

241-
try:
222+
if self.col_direction_cosine is not None:
242223
col_direction_cosine_attr = "Column Direction Cosine: " + str(self.col_direction_cosine) + "\n"
243224
result += col_direction_cosine_attr
244-
except AttributeError:
245-
pass
246225

247-
try:
226+
if self.depth_direction_cosine is not None:
248227
depth_direction_cosine_attr = "Depth Direction Cosine: " + str(self.depth_direction_cosine) + "\n"
249228
result += depth_direction_cosine_attr
250-
except AttributeError:
251-
pass
252229

253-
try:
230+
if self.dicom_affine_transform is not None:
254231
dicom_affine_transform_attr = "DICOM affine transform: " + "\n" + str(self.dicom_affine_transform) + "\n"
255232
result += dicom_affine_transform_attr
256-
except AttributeError:
257-
pass
258233

259-
try:
234+
if self.nifti_affine_transform is not None:
260235
nifti_affine_transform_attr = "NIFTI affine transform: " + "\n" + str(self.nifti_affine_transform) + "\n"
261236
result += nifti_affine_transform_attr
262-
except AttributeError:
263-
pass
264237

265238
result += "---------------" + "\n"
266239

0 commit comments

Comments
 (0)