Skip to content

Commit 433a3aa

Browse files
KumoLiujuampatronics
authored andcommitted
Fix Incorrect updated affine in NrrdReader and update docstring in 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]> Signed-off-by: Juan Pablo de la Cruz Gutiérrez <[email protected]>
1 parent d8236ea commit 433a3aa

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
@@ -168,8 +168,8 @@ class ITKReader(ImageReader):
168168
series_name: the name of the DICOM series if there are multiple ones.
169169
used when loading DICOM series.
170170
reverse_indexing: whether to use a reversed spatial indexing convention for the returned data array.
171-
If ``False``, the spatial indexing follows the numpy convention;
172-
otherwise, the spatial indexing convention is reversed to be compatible with ITK. Default is ``False``.
171+
If ``False``, the spatial indexing convention is reversed to be compatible with ITK;
172+
otherwise, the spatial indexing follows the numpy convention. Default is ``False``.
173173
This option does not affect the metadata.
174174
series_meta: whether to load the metadata of the DICOM series (using the metadata from the first slice).
175175
This flag is checked only when loading DICOM series. Default is ``False``.
@@ -1323,7 +1323,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:
13231323
header = dict(i.header)
13241324
if self.index_order == "C":
13251325
header = self._convert_f_to_c_order(header)
1326-
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(i)
1326+
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(header)
13271327

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

13451345
return _stack_images(img_array, compatible_meta), compatible_meta
13461346

1347-
def _get_affine(self, img: NrrdImage) -> np.ndarray:
1347+
def _get_affine(self, header: dict) -> np.ndarray:
13481348
"""
13491349
Get the affine matrix of the image, it can be used to correct
13501350
spacing, orientation or execute spatial transforms.
@@ -1353,8 +1353,8 @@ def _get_affine(self, img: NrrdImage) -> np.ndarray:
13531353
img: A `NrrdImage` loaded from image file
13541354
13551355
"""
1356-
direction = img.header["space directions"]
1357-
origin = img.header["space origin"]
1356+
direction = header["space directions"]
1357+
origin = header["space origin"]
13581358

13591359
x, y = direction.shape
13601360
affine_diam = min(x, y) + 1

0 commit comments

Comments
 (0)