[Neuroimaging] RGB Nifti

Fernando Pérez-García fepegar at gmail.com
Wed Feb 17 04:41:20 EST 2016


Hi Matthew,

Your solution worked (using copy). It took about 1 second, instead of the
40 it took using loops.

Thanks a lot for your help.


Best,

Fernando

2016-02-16 18:58 GMT+01:00 Matthew Brett <matthew.brett at gmail.com>:

> Hi,
>
> On Tue, Feb 16, 2016 at 9:17 AM, Ariel Rokem <arokem at gmail.com> wrote:
> > Gotcha.
> >
> > On Tue, Feb 16, 2016 at 8:53 AM, Fernando Pérez-García <
> fepegar at gmail.com>
> > wrote:
> >>
> >> Hi Ariel,
> >>
> >> data.shape is (5256, 3216, 3) at that point.
> >>
> >> If I do just
> >> nii = nib.Nifti1Image(data, np.eye(4))
> >> nib.save(nii, p.replace('png', 'nii')),
> >>
> >> I'll get a 3D nifti image with three slices, with one value per pixel. I
> >> want a 2D nifti image with one slice, three values per pixel. I do
> >> accomplish what I want with my code, but it's not very efficient. Do you
> >> think I should ask in the NumPy or SciPy mailing list?
> >
> >
> > You can certainly ask on these lists as well -- lots of knowledgable
> people
> > there.
> >
> > In the meanwhile, here's what I have managed to dig up on SO. Something
> > along these lines might work:
> >
> > http://stackoverflow.com/a/10016379/3532933
> >
> > But I don't have the full solution quite yet.
>
> How about:
>
> dt = np.dtype(zip('RGB', ('u1',) * 3))
> rgb_array = data.view(dt)   # You may need data.copy().view
> nii = nib.Nifti1Image(rgb_array, np.eye(4))
>
> ?
>
> Cheers,
>
> Matthew
> _______________________________________________
> 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/20160217/ec9e3072/attachment.html>


More information about the Neuroimaging mailing list