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

Dav Clark davclark at gmail.com
Tue Mar 28 14:45:37 EDT 2017


Unfortunately, there do seem to be some minor differences. I don't know if
they matter, but I'm unsettled that they are different at all...

To clarify, I'm starting with nifti pair images for each TR, so I used your
function, and then converted to Nifti1:

converted = nib.concat_images(fnames)
converted2 = nib.Nifti1Image.from_image(converted)

This version, upon saving with .to_filename() comes up in fslview as
totally black (the range is not calibrated for some reason - maybe there's
an errant bright voxel somewhere?). Compared to the results from `fslmerge
-t fnames`, setting the range the same for voxel intensities, I get the
same images, and the same time-series shape. However, intensities are
slightly off (even in the same TR) by values ranging from hundreds to
thousands (the raw intensities are in 100,000's). So, usually < 1% I
suspect.

Is this worth getting to the bottom of? Happy to share some EPIs with you
somewhere... by default I would use JHU Box.

Best,
Dav

On Tue, Mar 28, 2017 at 1:55 PM, Dav Clark <davclark at gmail.com> wrote:

> 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/22cff59b/attachment.html>


More information about the Neuroimaging mailing list