@@ -580,7 +580,7 @@ def _combine_dicom_series(self, data: Iterable, filenames: Sequence[PathLike]):
580580 shape = first_array .shape
581581 spacing = getattr (first_slice , "PixelSpacing" , [1.0 ] * len (shape ))
582582 prev_pos = getattr (first_slice , "ImagePositionPatient" , (0.0 , 0.0 , 0.0 ))[2 ]
583- stack_array = [first_array ]
583+ stack_array_list : list = [first_array ]
584584 for idx in range (1 , len (slices )):
585585 slc_array = self ._get_array_data (slices [idx ][0 ], slices [idx ][1 ])
586586 slc_shape = slc_array .shape
@@ -592,22 +592,24 @@ def _combine_dicom_series(self, data: Iterable, filenames: Sequence[PathLike]):
592592 warnings .warn (f"the list contains slices that have different shapes { shape } and { slc_shape } ." )
593593 average_distance += abs (prev_pos - slc_pos )
594594 prev_pos = slc_pos
595- stack_array .append (slc_array )
595+ stack_array_list .append (slc_array )
596596
597597 if len (slices ) > 1 :
598598 average_distance /= len (slices ) - 1
599599 spacing .append (average_distance )
600600 if self .to_gpu :
601- stack_array = cp .stack (stack_array , axis = - 1 )
601+ stack_array = cp .stack (stack_array_list , axis = - 1 )
602602 else :
603- stack_array = np .stack (stack_array , axis = - 1 )
603+ stack_array = np .stack (stack_array_list , axis = - 1 )
604+
605+ del stack_array_list [:]
604606 stack_metadata = self ._get_meta_dict (first_slice )
605607 stack_metadata ["spacing" ] = np .asarray (spacing )
606608 if hasattr (slices [- 1 ][0 ], "ImagePositionPatient" ):
607609 stack_metadata ["lastImagePositionPatient" ] = np .asarray (slices [- 1 ][0 ].ImagePositionPatient )
608610 stack_metadata [MetaKeys .SPATIAL_SHAPE ] = shape + (len (slices ),)
609611 else :
610- stack_array = stack_array [0 ]
612+ stack_array = stack_array_list [0 ]
611613 stack_metadata = self ._get_meta_dict (first_slice )
612614 stack_metadata ["spacing" ] = np .asarray (spacing )
613615 stack_metadata [MetaKeys .SPATIAL_SHAPE ] = shape
0 commit comments