I have RGB images which I'm loading as a numpy array. I would like to convert these images into the nifty format, which I can open using ITK-SNAP (http://www.itksnap.org/pmwiki/pmwiki.php).
Here is what I have tried to do:
import nibabel as nib
import numpy as np
x = load_jpg_image(filename='input.jpg') # --> x is a numpy array containing the RGB image with shape (128, 128, 3)
img = nib.Nifti1Image(x, eye(4))
nib.save(img, filename='output.nii')
However, ITK-SNAP interprets output.nii
as a 3D grayscale volume rather than an RGB image. To me, it seems that ITK-SNAP should be able to handle RGB data (see this); however, I don't understand how I should save img
to make this possible. I'm using ITK-SNAP 3.6.0.