Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
function2-llx committed Jun 27, 2023
1 parent 0ffe55a commit 9e2a0db
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,19 @@ def _combine_dicom_series(self, data: Iterable):
first_array = self._get_array_data(first_slice)
shape = first_array.shape
spacing = getattr(first_slice, "PixelSpacing", [1.0, 1.0, 1.0])
pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, 0.0))[2]
prev_pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, 0.0))[2]
stack_array = [first_array]
for idx in range(1, len(slices)):
slc_array = self._get_array_data(slices[idx])
slc_shape = slc_array.shape
slc_spacing = getattr(first_slice, "PixelSpacing", (1.0, 1.0, 1.0))
slc_pos = getattr(first_slice, "ImagePositionPatient", (0.0, 0.0, float(idx)))[2]
if spacing != slc_spacing:
slc_spacing = getattr(slices[idx], "PixelSpacing", (1.0, 1.0, 1.0))
slc_pos = getattr(slices[idx], "ImagePositionPatient", (0.0, 0.0, float(idx)))[2]
if not np.allclose(slc_spacing, spacing):
warnings.warn(f"the list contains slices that have different spacings {spacing} and {slc_spacing}.")
if shape != slc_shape:
warnings.warn(f"the list contains slices that have different shapes {shape} and {slc_shape}.")
average_distance += abs(pos - slc_pos)
pos = slc_pos
average_distance += abs(prev_pos - slc_pos)
prev_pos = slc_pos
stack_array.append(slc_array)

if len(slices) > 1:
Expand Down

0 comments on commit 9e2a0db

Please sign in to comment.