[Neuroimaging] [DiPy] Registration problem integer image arrays

Pietro Astolfi pietroastolfi92 at gmail.com
Thu May 3 04:57:58 EDT 2018


Hi,

You can use uint16 for both the images when you load them. Then if the images are nifti files you don’t need to transform them to array, you should use the class method .get_data() to extract the numpy array from the loaded image. I give you a practice working example with c_of_mass:

import nibabel as nib
import numpy as np
from dipy.align.imaffine import transform_centers_of_mass

# static image
img1 = nib.load(‘img1.nii.gz’)
img1_data = img1.get_data() #now img1_data is a numpy array of float
img1_data = img1_data.as_type(np.uint16)
aff1 = img1.affine

# moving image
img2 = nib.load(‘img2.nii.gz’)
img2_data = img2.get_data() #now img2_data is a numpy array of float
img2_data = img2_data.as_type(np.uint16)
aff2 = img2.affine

c_of_mass = transform_centers_of_mass(img1_data, aff1, img2_data, aff2)

transformed = c_of_mass.transform(img2_data) # note that transform function cast the input array (img2_data here) as np.float64 in order to interpolate, so the returned array (transformed here) is a float64

let me know if this helps you.

Pietro

> Il giorno 03 mag 2018, alle ore 09:04, Bene Wiestler <b.wiestler at tum.de> ha scritto:
> 
> Hi,
> 
> I have a problem with the dipy image registration workflow:
> I want to register two anatomical images using linear methods (c_of_mass, translation, rigid). One file is a uint16 data type, the other is saved as a float, however essentially also only contains integer. When I load these files with nibabel and convert the data arrays to int16 (both with the .astype(np-int16) methods and with numpy.asarray), registration (even c_of_mass) always yields an empty transformed moving image (i.e. just containing 0s). However, when I save the files using the converted int16 data arrays and open them in e.g. ITK-Snap, they look fine.
> When I convert both files to float32, registration works, but is slow.
> Further, when I run your example script for affine registration with the files provided there (Stanford; syn; both int16), it works fine for these files.
> Has anybody any idea what might be a solution other than just float32?
> 
> Thanks a lot!
> 
> Bene
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging



More information about the Neuroimaging mailing list