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

nifti saver squeeze dims #1680

Merged
merged 2 commits into from
Mar 3, 2021
Merged

Conversation

rijobro
Copy link
Contributor

@rijobro rijobro commented Mar 3, 2021

Fixes #1678.

Description

Currently NiftiSaver (therefore default SaveImage and SaveImaged) saves images as (H,W,D,C), even if input image had no channel dimension, or was only a 2D image.

This PR allows users to squeeze trailing singleton dimensions. If C==1, image will be saved as (H,W,D). If D is also == 1, image will be saved as (H,W). If D==1, but C>1, image will still be saved as (H,W,D,C) (to avoid channel dimension being interpreted as depth).

I also changed the saved path from /some/path/filename/filename.nii.gz to /some/path/filename.nii.gz, as I assumed the former was a mistake. I can undo this if it was intentional. EDIT: I reverted this for backwards compatibility, but I still find it ugly.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh --codeformat --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro
Copy link
Contributor Author

rijobro commented Mar 3, 2021

fixes #1677.

@rijobro rijobro requested review from Nic-Ma and wyli and removed request for Nic-Ma March 3, 2021 13:23
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! looks good to me. (there's a similar workaround in niftynet https://github.com/NifTK/NiftyNet/blob/935bf4334cd00fa9f9d50f6a95ddcbfdde4031e0/niftynet/io/misc_io.py#L441-L450 proposed by @hjmjohnson )

@wyli
Copy link
Contributor

wyli commented Mar 3, 2021

for the file path, I think it's originally from Clara Train where we want to save some other relevant predictions along with each .nii.gz file, /some/path/filename is a default folder to collect those predictions

@rijobro rijobro enabled auto-merge (squash) March 3, 2021 13:56
@rijobro rijobro merged commit 27543c8 into Project-MONAI:master Mar 3, 2021
@rijobro rijobro deleted the nifti_saver_squeeze branch March 3, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants