Skip to content

Handle RGB(A) data with get_fdata() #979

Open
@pwrightkcl

Description

@pwrightkcl

I am working with clinical data that includes a wide range of image types. When I encounter an image with RGB data, for example a screenshot, nibabel fails to load the image data. I am able to view the image in MRIcron.
Steps to reproduce:

import nibabel as nib
rgbimage = nib.load(rgbimagefilename)
print(rgbimage.get_data_dtype())
[('R', 'u1'), ('G', 'u1'), ('B', 'u1')]
imagedata = rgbimage.get_fdata()
Traceback (most recent call last):
  File "/home/me/.local/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-119-57f46d1e6598>", line 1, in <module>
    iamgedata = rgbimage.get_fdata()
  File "/home/me/.local/lib/python3.8/site-packages/nibabel/dataobj_images.py", line 355, in get_fdata
    data = np.asanyarray(self._dataobj, dtype=dtype)
  File "/home/me/.local/lib/python3.8/site-packages/numpy/core/_asarray.py", line 136, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions