[Neuroimaging] Apply resolution of one image.nii to another image.nii

Matthew Brett matthew.brett at gmail.com
Fri Jan 11 11:00:12 EST 2019


Hi,


On Fri, Jan 11, 2019 at 3:26 PM Eric Condamine
<eric.condamine at univ-grenoble-alpes.fr> wrote:
>
> Hello nipy experts,
> I would like to change the resolution of an nifti image (let's say mask.nii) according to the resolution of one other nifti image (let's say ref.nii), a process that i was doing with the imcalc function of spm before i start to switch to python ... i confess that i do not yet know all the tools currently available under nipy umbrella ...
> One way to do it could be something like that.
>
> """
> from skimage.transform import resize
> import nibabel as nib
>
> mask = nib.load(mask.nii)
> mask_data = mask.get_fdata()
>
> ref = nib.load(ref.nii)
> ref_data = ref.get_fdata()
>
> ref_size = ref_data.shape[:3]
> resized_mask_data = resize(mask_data, ref_size, order=1, mode='reflect') # order=1 (Bi-linear) is the default value and it seems that with 3D image, Bi-linear is equivalent to 'trilinear' of SPM's imcalc function ?

Did you discover the processing module in nibabel?

Maybe "resample_from_to" would help:

http://nipy.org/nibabel/reference/nibabel.processing.html#nibabel.processing.resample_from_to

Something like:

import nibabel.processing as nibp
resized = nibp.resample_from_to(mask, ref)

Does that work?  You'd probably have to threshold the image binarize
it - trilinear resampling is the default - or use 0 (nearest neighbor)
resampling.

Cheers,

Matthew


More information about the Neuroimaging mailing list