-
Notifications
You must be signed in to change notification settings - Fork 53
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
Embedding of meta data does not work for multi channel (RGB) data #74
Comments
This issue could be fixed at different places in dcmstack e.g. import nibabel as nib
import numpy as np
old_init = nib.nifti1.Nifti1Image.__init__
def new_init(
self: nib.nifti1.Nifti1Image,
dataobj: np.ndarray,
affine: np.ndarray,
*args,
**kwargs,
):
has_rgb_channel = dataobj.shape[-1] == 3
if has_rgb_channel:
rgb_dtype = np.dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')])
dataobj = dataobj.copy().view(dtype=rgb_dtype) # type: ignore
old_init(self, dataobj, affine, *args, **kwargs) # type: ignore
if has_rgb_channel:
self.header.set_intent(code=2003) # type: ignore
nib.nifti1.Nifti1Image.__init__ = new_init
import dcmstack I hope that helps. |
Does Nifti have a spec for RGB, or is there any software that works with RGB Nifti files? This isn't something I can imagine needing myself, but if someone else wants to create a good PR I can review and merge. |
Not sure where to look for the official Nifti Spec but here RGB is mentioned: https://brainder.org/2012/09/23/the-nifti-file-format/ We often work with MRIcroGL and I believe it's able to display RGB NIfTIs. I think I did read that ITK-snap can also read them. Maybe I can upload an example image next week(s). |
Pretext: I'm painfully aware that this package is no longer maintained. But we have no alternative and our only hope is to wait patiently for nipy/nibabel#977. I'm still reporting this bug here so it might be taken into consideration in the nibabel implementation.
For a 3D RGB image with shape [192, 256, 256, 3] the individual DICOM files (slices) have a shape of [256, 256, 3].
The method
DcmMetaExtension.from_sequence
currently can't handle a channel dimension.It then fails at line 611 in
dcmmeta.py
:where
input_shape
is [256, 256, 3],len(input_shape)
is 3 butdim
is 2.The text was updated successfully, but these errors were encountered: