Skip to content

Conversation

@rijobro
Copy link
Contributor

@rijobro rijobro commented Mar 1, 2021

Fixes #1664.

Description

Image meta data seems to cause a problem when a nifti image s big endian. This means that the dictionary LoadImaged fails for big endian nifti images, whilst LoadImage doesn't.

This is fixed by recursively traversing the meta data and switching any numpy endianness from ">" to "<".

In this PR I've added the option for image_only with LoadImaged.

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.
  • Quick tests passed locally by running ./runtests.sh --quick.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

rijobro added 2 commits March 1, 2021 11:29
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro
Copy link
Contributor Author

rijobro commented Mar 1, 2021

@chrisfoulon I think this should work. Might need to be extended to native endian ("=") if the native endianness is big endian (">"). Can you give this a try and let me know? Looks like you were using 0.4.0 before, so there may be other things in the pipeline that have changed in the meantime, e.g., NiftiDataset no longer exists (replaced by ImageDataset).

@rijobro
Copy link
Contributor Author

rijobro commented Mar 1, 2021

Note to self, might be this:

if data.dtype.byteorder == "=" and sys.byteorder != "little":
    data = data.newbyteorder("<")

rijobro added 3 commits March 1, 2021 16:06
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro
Copy link
Contributor Author

rijobro commented Mar 1, 2021

@wyli @Nic-Ma Could anyone help me with the CI error? It's complaining about the use of optional_import("nibabel") and hdr = nib.Nifti1Header(endianness=endianness).

The nib.Nifti1Header(endianness=endianness) statement is inside of a @skipUnless(has_nib) decorator, so I don't understand.

@wyli
Copy link
Contributor

wyli commented Mar 1, 2021

@wyli @Nic-Ma Could anyone help me with the CI error? It's complaining about the use of optional_import("nibabel") and hdr = nib.Nifti1Header(endianness=endianness).

The nib.Nifti1Header(endianness=endianness) statement is inside of a @skipUnless(has_nib) decorator, so I don't understand.

would swap the skip and expand decorators work?

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

rijobro commented Mar 1, 2021

would swap the skip and expand decorators work?

That seems to have worked, thanks!

rijobro added 3 commits March 1, 2021 18:17
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro rijobro enabled auto-merge (squash) March 2, 2021 11:29
@rijobro rijobro merged commit 20e17b2 into Project-MONAI:master Mar 2, 2021
@rijobro rijobro deleted the nifti_endianness branch March 2, 2021 12:06
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.

Numpy byte order conversion error with Dataset and dictionaries

3 participants