@@ -139,9 +139,7 @@ def uncompress_file(self, num_files, form):
139139 """unzip all the file in the root directory"""
140140 files = glob .glob (os .path .join (self .dataset_root , "*.{}" .format (form )))
141141
142- assert len (files ) == num_files , print (
143- "The file directory should include {} compressed files, but there is only {}"
144- .format (num_files , len (files )))
142+ assert len (files ) == num_files , "The file directory should include {} compressed files, but there is only {}" .format (num_files , len (files ))
145143
146144 for f in files :
147145 extract_path = os .path .join (self .raw_data_path ,
@@ -162,24 +160,23 @@ def load_medical_data(f):
162160
163161 # validate nii.gz on lung and mri with correct spacing_resample
164162 if filename .endswith ((".nii" , ".nii.gz" , ".dcm" )):
165- itkimage = sitk .ReadImage (f )
166- if itkimage .GetDimension () == 4 :
167- slicer = sitk .ExtractImageFilter ()
168- s = list (itkimage .GetSize ())
169- s [- 1 ] = 0
170- slicer .SetSize (s )
171- for slice_idx in range (itkimage .GetSize ()[- 1 ]):
172- slicer .SetIndex ([0 , 0 , 0 , slice_idx ])
173- sitk_volume = slicer .Execute (itkimage )
174- images .append (sitk_volume )
163+ if "radiopaedia" in filename or "corona" in filename :
164+ f_nps = [nib .load (f ).get_fdata (dtype = np .float32 )]
175165 else :
176- images = [itkimage ]
177- images = [sitk .DICOMOrient (img , 'LPS' ) for img in images ]
178- f_nps = [sitk .GetArrayFromImage (img ) for img in images ]
179-
180- # if previous line not swap to xyz
181- if f_nps [0 ].shape [0 ] != f_nps [0 ].shape [1 ]:
182- f_nps = [np .transpose (f_np , [1 , 2 , 0 ]) for f_np in f_nps ] # swap to xyz
166+ itkimage = sitk .ReadImage (f )
167+ if itkimage .GetDimension () == 4 :
168+ slicer = sitk .ExtractImageFilter ()
169+ s = list (itkimage .GetSize ())
170+ s [- 1 ] = 0
171+ slicer .SetSize (s )
172+ for slice_idx in range (itkimage .GetSize ()[- 1 ]):
173+ slicer .SetIndex ([0 , 0 , 0 , slice_idx ])
174+ sitk_volume = slicer .Execute (itkimage )
175+ images .append (sitk_volume )
176+ else :
177+ images = [itkimage ]
178+ images = [sitk .DICOMOrient (img , 'LPS' ) for img in images ]
179+ f_nps = [sitk .GetArrayFromImage (img ) for img in images ]
183180
184181 elif filename .endswith (
185182 (".mha" , ".mhd" , "nrrd"
0 commit comments