Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #6630 #6660

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
data: file name or a list of file names to read,
kwargs: additional args for `itk.imread` API, will override `self.kwargs` for existing keys.
More details about available args:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/itkExtras.py
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/itk/support/extras.py

"""
img_ = []
Expand All @@ -230,7 +230,7 @@ def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
name = f"{name}"
if Path(name).is_dir():
# read DICOM series
# https://itk.org/ITKExamples/src/IO/GDCM/ReadDICOMSeriesAndWrite3DImage
# https://examples.itk.org/src/io/gdcm/readdicomseriesandwrite3dimage/documentation
names_generator = itk.GDCMSeriesFileNames.New()
names_generator.SetUseSeriesDetails(True)
names_generator.AddSeriesRestriction("0008|0021") # Series Date
Expand Down 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