[Neuroimaging] Using nibabel to merge 3D image pairs into single-file 4D Nifti1

Dav Clark davclark at gmail.com
Tue Mar 28 13:55:11 EDT 2017


Regarding archiving the mailing list, it'd actually be really easy to use
this:

https://www.mail-archive.com/faq.html#newlist

I am almost certain that your proposed solution will work. I suppose this
means the documentation could be improved, but I'm not sure how to address
it. Maybe having a list with all functions and their short description on
one page?

I'll report back if there's a problem anyway. Otherwise, assume your
solution worked.

Thanks for your quick response!
D


On Fri, Mar 24, 2017 at 5:10 PM, Matthew Brett <matthew.brett at gmail.com>
wrote:

> Hi,
>
> On Fri, Mar 24, 2017 at 8:57 PM, Dav Clark <davclark at gmail.com> wrote:
> > So, this is a post on stack overflow:
> >
> > http://stackoverflow.com/questions/33737282/copy-
> header-when-merging-multiple-mri-images-using-nibabel
> >
> > I'm doing something more or less equivalent:
> >
> > ```
> > sample_path = 'some_path/some_sub*.hdr'
> > fnames = glob(sample_path)
> > imgs = [nib.load(fn) for fn in fnames]
> >
> > img_data = np.stack([img.dataobj for img in imgs], axis=-1)
> >
> > converted = nib.Nifti1Image(img_data, imgs[0].affine, imgs[0].header)
> > converted.to_filename('some_filename.nii.gz')
> > ```
> >
> > But the output ends up having a severely restricted range (thus
> > rendering by default as black in fslview) as compared to fslmerge -t.
> > fslmerge gets the TR right, and the nibabel version sets TR (pixdim4)
> > to 1.0. Moreover imgs[0].header.get_slice_times() results in an error.
> >
> > Also, while the dimensions appear to be the same, I get different
> > shaped time-series (as well as different absolute values, of course)
> > from the two different conversion paths. I suspect I'm missing a
> > scaling parameter from the files.
> >
> > For now, I am just using fslmerge -t, but since at least some other
> > person out there has also done this (see so question linked above), I
> > figure it's worth asking.
> >
> > If I could get this to work, it becomes very easy to implement in dask
> > and take advantage of the spiffy computer I now have access to...
>
> Did you try:
>
> converted = nib.concat_images(fnames)
>
> ? I guess the correct TR and slice timing info is correctly set in the
> first image header - I mean:
>
> first_header = nib.load(fnames[0]).header
>
> > ps - is there a searchable archive of the list? If not, I have a buddy
> > who is pretty facile with mailman listservs...
>
> Actually, no, I don't think we have - would be very glad of help.
> We're using the same python.org mailman hosting as scipy and numpy, so
> a general solution would be generally useful.
>
> 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/20170328/08708f8c/attachment.html>


More information about the Neuroimaging mailing list