[Neuroimaging] RGB Nifti

Ariel Rokem arokem at gmail.com
Tue Feb 16 11:46:33 EST 2016


Hi Fernando,

Just trying to understand what you are trying to achieve:

On Tue, Feb 16, 2016 at 8:44 AM, Fernando Pérez-García <fepegar at gmail.com>
wrote:

> Hi Paulo,
>
> Thanks for your response. It seems that ConvertScalarImageToRGB reads a
> gray nifti and makes an RGB nifti (using ITK) with a certain colormap. The
> image I'm reading is a PNG file already RGB, as you can see in my code, so
> I think ANTS won't help here.
>
>
> Cheers,
>
> Fernando
>
> 2016-02-16 17:32 GMT+01:00 paulo rodrigues <khamael at gmail.com>:
>
>> Hi Fernando,
>>
>> Did you have a look at ants? It has some tools for that kind of
>> operations: check ConvertScalarImageToRGB
>>
>> Cheers,
>> Paulo
>>
>> On Tue, Feb 16, 2016 at 5:05 PM, Fernando Pérez-García <fepegar at gmail.com
>> > wrote:
>>
>>> Dear Nibabel experts,
>>>
>>> I'm trying to create an RGB nifti image from a PNG file. I've been
>>> messing around with a working RGB nifti, in order to mimic the datatype
>>> found in its header. So far I've managed to convert the image pixel-wise
>>> with for loops, which is very slow. Do you know how this could be done in a
>>> faster way?
>>>
>>>
>>> My code:
>>>
>>> import numpy as np
>>> import Image
>>> import nibabel as nib
>>>
>>> p = '/home/fernando/test/nii_rgb/TC1.png'
>>> im = Image.open(p)
>>>
>>> data = np.array(im)
>>> data = np.rot90(data)
>>>
>>
What is `data.shape` at this point?

Why wouldn't the following work?

    nii = nib.Nifti1Image(data, np.eye(4))
    nib.save(nii, p.replace('png', 'nii'))

Cheers,

Ariel


> rgb = np.zeros((data.shape[0], data.shape[1], 1, 1), [('R', 'u1'), ('G',
>>> 'u1'), ('B', 'u1')])
>>>
>>> for i in range(data.shape[0]):
>>>     for j in range(data.shape[1]):
>>>         rgb[i, j] = tuple(data[i, j, :])
>>>
>>> nii = nib.Nifti1Image(rgb, np.eye(4))
>>> nib.save(nii, p.replace('png', 'nii'))
>>>
>>>
>>>
>>> Thanks in advance,
>>>
>>> Fernando
>>>
>>> _______________________________________________
>>> Neuroimaging mailing list
>>> Neuroimaging at python.org
>>> https://mail.python.org/mailman/listinfo/neuroimaging
>>>
>>>
>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160216/e1926b5a/attachment.html>


More information about the Neuroimaging mailing list