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

Dav Clark davclark at gmail.com
Fri Mar 24 16:57:41 EDT 2017


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...

Thanks!
Dav

ps - is there a searchable archive of the list? If not, I have a buddy
who is pretty facile with mailman listservs...


More information about the Neuroimaging mailing list