Skip to content

Fix Incorrect updated affine in NrrdReader and update docstring in ITKReader #7415

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

Merged
merged 2 commits into from
Jan 25, 2024
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
12 changes: 6 additions & 6 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class ITKReader(ImageReader):
series_name: the name of the DICOM series if there are multiple ones.
used when loading DICOM series.
reverse_indexing: whether to use a reversed spatial indexing convention for the returned data array.
If ``False``, the spatial indexing follows the numpy convention;
otherwise, the spatial indexing convention is reversed to be compatible with ITK. Default is ``False``.
If ``False``, the spatial indexing convention is reversed to be compatible with ITK;
otherwise, the spatial indexing follows the numpy convention. Default is ``False``.
This option does not affect the metadata.
series_meta: whether to load the metadata of the DICOM series (using the metadata from the first slice).
This flag is checked only when loading DICOM series. Default is ``False``.
Expand Down Expand Up @@ -1323,7 +1323,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:
header = dict(i.header)
if self.index_order == "C":
header = self._convert_f_to_c_order(header)
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(i)
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(header)

if self.affine_lps_to_ras:
header = self._switch_lps_ras(header)
Expand All @@ -1344,7 +1344,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:

return _stack_images(img_array, compatible_meta), compatible_meta

def _get_affine(self, img: NrrdImage) -> np.ndarray:
def _get_affine(self, header: dict) -> np.ndarray:
"""
Get the affine matrix of the image, it can be used to correct
spacing, orientation or execute spatial transforms.
Expand All @@ -1353,8 +1353,8 @@ def _get_affine(self, img: NrrdImage) -> np.ndarray:
img: A `NrrdImage` loaded from image file

"""
direction = img.header["space directions"]
origin = img.header["space origin"]
direction = header["space directions"]
origin = header["space origin"]

x, y = direction.shape
affine_diam = min(x, y) + 1
Expand Down