Skip to content

Commit

Permalink
Fix Incorrect updated affine in NrrdReader and update docstring in …
Browse files Browse the repository at this point in the history
…`ITKReader` (Project-MONAI#7415)

Fixes Project-MONAI#7414
Fixes Project-MONAI#7371


### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <[email protected]>
  • Loading branch information
KumoLiu authored Jan 25, 2024
1 parent abe2e31 commit 6c9e49e
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 @@ -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

0 comments on commit 6c9e49e

Please sign in to comment.