@@ -536,7 +536,10 @@ def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
536536 else :
537537 ds = pydicom .dcmread (fp = name , ** kwargs_ )
538538 img_ .append (ds )
539- return img_ if len (filenames ) > 1 else img_ [0 ]
539+ if len (filenames ) == 1 :
540+ self .filenames = self .filenames [0 ] # type: ignore
541+ return img_ [0 ]
542+ return img_
540543
541544 def _combine_dicom_series (self , data : Iterable , filenames : Sequence [PathLike ]):
542545 """
@@ -564,22 +567,21 @@ def _combine_dicom_series(self, data: Iterable, filenames: Sequence[PathLike]):
564567 else :
565568 warnings .warn (f"slice: { filename } does not have InstanceNumber tag, skip it." )
566569 slices = sorted (slices , key = lambda s : s [0 ].InstanceNumber )
567-
568570 if len (slices ) == 0 :
569571 raise ValueError ("the input does not have valid slices." )
570572
571573 first_slice , first_filename = slices [0 ]
572574 average_distance = 0.0
573575 first_array = self ._get_array_data (first_slice , first_filename )
574576 shape = first_array .shape
575- spacing = getattr (first_slice , "PixelSpacing" , [1.0 , 1.0 , 1.0 ] )
577+ spacing = getattr (first_slice , "PixelSpacing" , [1.0 ] * len ( shape ) )
576578 prev_pos = getattr (first_slice , "ImagePositionPatient" , (0.0 , 0.0 , 0.0 ))[2 ]
577579 stack_array = [first_array ]
578580 for idx in range (1 , len (slices )):
579581 slc_array = self ._get_array_data (slices [idx ][0 ], slices [idx ][1 ])
580582 slc_shape = slc_array .shape
581- slc_spacing = getattr (slices [idx ], "PixelSpacing" , ( 1.0 , 1.0 , 1.0 ))
582- slc_pos = getattr (slices [idx ], "ImagePositionPatient" , (0.0 , 0.0 , float (idx )))[2 ]
583+ slc_spacing = getattr (slices [idx ][ 0 ] , "PixelSpacing" , [ 1.0 ] * len ( shape ))
584+ slc_pos = getattr (slices [idx ][ 0 ] , "ImagePositionPatient" , (0.0 , 0.0 , float (idx )))[2 ]
583585 if not np .allclose (slc_spacing , spacing ):
584586 warnings .warn (f"the list contains slices that have different spacings { spacing } and { slc_spacing } ." )
585587 if shape != slc_shape :
0 commit comments