Skip to content

Commit 9e2a0db

Browse files
function2function2-llx
authored andcommitted
fix #6630
1 parent 0ffe55a commit 9e2a0db

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

monai/data/image_reader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,19 @@ def _combine_dicom_series(self, data: Iterable):
512512
first_array = self._get_array_data(first_slice)
513513
shape = first_array.shape
514514
spacing = getattr(first_slice, "PixelSpacing", [1.0, 1.0, 1.0])
515-
pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, 0.0))[2]
515+
prev_pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, 0.0))[2]
516516
stack_array = [first_array]
517517
for idx in range(1, len(slices)):
518518
slc_array = self._get_array_data(slices[idx])
519519
slc_shape = slc_array.shape
520-
slc_spacing = getattr(first_slice, "PixelSpacing", (1.0, 1.0, 1.0))
521-
slc_pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, float(idx)))[2]
522-
if spacing != slc_spacing:
520+
slc_spacing = getattr(slices[idx], "PixelSpacing", (1.0, 1.0, 1.0))
521+
slc_pos = getattr(slices[idx], "ImagePositionPatient", (0.0, 0.0, float(idx)))[2]
522+
if not np.allclose(slc_spacing, spacing):
523523
warnings.warn(f"the list contains slices that have different spacings {spacing} and {slc_spacing}.")
524524
if shape != slc_shape:
525525
warnings.warn(f"the list contains slices that have different shapes {shape} and {slc_shape}.")
526-
average_distance += abs(pos - slc_pos)
527-
pos = slc_pos
526+
average_distance += abs(prev_pos - slc_pos)
527+
prev_pos = slc_pos
528528
stack_array.append(slc_array)
529529

530530
if len(slices) > 1:

0 commit comments

Comments
 (0)