Skip to content

Commit

Permalink
Fix negative strides issue in NrrdReader (Project-MONAI#7809)
Browse files Browse the repository at this point in the history
Fixes Project-MONAI#7798

### Description

Add copy to avoid negative strides when save spatial shape.

### 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 <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
  • Loading branch information
KumoLiu and ericspod authored May 28, 2024
1 parent 762b525 commit a0935d9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:
header[MetaKeys.SPACE] = SpaceKeys.LPS # assuming LPS if not specified

header[MetaKeys.AFFINE] = header[MetaKeys.ORIGINAL_AFFINE].copy()
header[MetaKeys.SPATIAL_SHAPE] = header["sizes"]
header[MetaKeys.SPATIAL_SHAPE] = header["sizes"].copy()
[header.pop(k) for k in ("sizes", "space origin", "space directions")] # rm duplicated data in header

if self.channel_dim is None: # default to "no_channel" or -1
Expand Down

0 comments on commit a0935d9

Please sign in to comment.