@@ -71,10 +71,11 @@ def __call__(self, inference_pipeline) -> Dict[str, Path]:
71
71
class DicomToNifti (InferenceClass ):
72
72
"""Convert dicom files to NIfTI files."""
73
73
74
- def __init__ (self , input_path : Union [str , Path ], save = True ):
74
+ def __init__ (self , input_path : Union [str , Path ], pipeline_name = None , save = True ):
75
75
super ().__init__ ()
76
76
self .input_path = Path (input_path )
77
77
self .save = save
78
+ self .pipeline_name = pipeline_name
78
79
79
80
def __call__ (self , inference_pipeline ):
80
81
if os .path .exists (
@@ -114,24 +115,27 @@ def __call__(self, inference_pipeline):
114
115
return {}
115
116
116
117
117
- def series_selector (dicom_path ):
118
+ def series_selector (dicom_path , pipeline_name = None ):
118
119
ds = pydicom .filereader .dcmread (dicom_path )
119
120
image_type_list = list (ds .ImageType )
120
- if not any ("primary" in s .lower () for s in image_type_list ):
121
- raise ValueError ("Not primary image type" )
122
- if not any ("original" in s .lower () for s in image_type_list ):
123
- raise ValueError ("Not original image type" )
121
+ if pipeline_name and (pipeline_name != "aaa" ):
122
+ if not any ("primary" in s .lower () for s in image_type_list ):
123
+ raise ValueError ("Not primary image type" )
124
+ if not any ("original" in s .lower () for s in image_type_list ):
125
+ raise ValueError ("Not original image type" )
126
+ else :
127
+ print (f"Skipping primary and original image type check for the { pipeline_name } pipeline." )
124
128
# if any("gsi" in s.lower() for s in image_type_list):
125
129
# raise ValueError("GSI image type")
126
130
if ds .ImageOrientationPatient != [1 , 0 , 0 , 0 , 1 , 0 ]:
127
131
raise ValueError ("Image orientation is not axial" )
128
132
return ds
129
133
130
134
131
- def dicom_series_to_nifti (input_path , output_file , reorient_nifti ):
135
+ def dicom_series_to_nifti (input_path , output_file , reorient_nifti , pipeline_name = None ):
132
136
reader = sitk .ImageSeriesReader ()
133
137
dicom_names = reader .GetGDCMSeriesFileNames (str (input_path ))
134
- ds = series_selector (dicom_names [0 ])
138
+ ds = series_selector (dicom_names [0 ], pipeline_name = pipeline_name )
135
139
reader .SetFileNames (dicom_names )
136
140
image = reader .Execute ()
137
141
sitk .WriteImage (image , output_file )
0 commit comments