Added proper handling of nifti RGB formats#46
Conversation
1. The format of (x, y, z, t, (uint8, uint8, uint8)) is supported and
mmap works out of the box
2. The format of (x, y, z, t, [('R', 'u1'), ('G', 'u1'), ('B', 'u1')])
structured rgb format is also supported. However, due to limitation
of nibabel, the full dataset need to be loaded into memory.
A warning is printed for this case
|
@baishi thanks for the PR. Is there a sample nifti where we can write test to prevent regression in the future? |
I have attached two sample image to test against. |
xgui3783
left a comment
There was a problem hiding this comment.
Apologies it took so long.
Thanks for the PR.
If you find you have less time, feel free to edit the PR to allow maintainers to change the PR, so we can update the proposed change.
| @@ -325,6 +371,7 @@ def volume_file_to_precomputed(volume_filename, | |||
| new_proxy[2*third:] | |||
| ], axis=-1) | |||
| img = nibabel.Nifti1Image(new_dataobj, img.affine) | |||
| """ | |||
There was a problem hiding this comment.
we can just remove this bit, right?
| "does not lose range/accuracy.", | ||
| input_dtype.name, output_dtype.name) | ||
| if input_dtype == [('R', 'u1'), ('G', 'u1'), ('B', 'u1')]: | ||
| # numpy cannot case RGB*u1 to uint8, the rgb structure need to be handled separately |
| logger.warning('The mmap access for structured RGB nifti format is not supported, reading all data into memory') | ||
| logger.warning('This process may use a lot of memory, be warned') | ||
| volume = proxy[:].view(dtype=np.uint8, type=np.ndarray).reshape(proxy.shape[0:4] + (3,)) |
There was a problem hiding this comment.
hmm, my personal expectation is that it should raise, with how to remedy (aka, omit --mmap flag, and expect logs of memory usage)
|
|
||
|
|
||
| # RGB nifti file has two arrangements, number 1 datatype as integer values with axis 4 to be the components | ||
| # the other type is datatype == 128, then the data is stored structurally |
There was a problem hiding this comment.
is there a doc for this? if we do, it would be great to reference it here.
Two formats of NIfTI are properly supported
A warning is printed for this case