how to use the affine transform results when writing a registered image
Hi, I'm using dipy functions to coregister a T1 to the MNI T1 template, by pretty much copying what's in the documentation page https://dipy.org/documentation/1.2.0./examples_index/#registration: static, static_affine = load_nifti( template_mr ); moving, moving_affine = load_nifti( mr_filename ); # first initialise by putting centres of mass on top of each other c_of_mass = transform_centers_of_mass ( static, static_affine, moving, moving_affine ); # initialise transform parameters (e.g. the mutual information criterion) # these parameters won' need to be changed between the different stages nbins = 64 sampling_prop = None metric = MutualInformationMetric ( nbins, sampling_prop ); level_iters = [ 100, 50, 10 ]; sigmas = [ 2.0, 1.0, 0.0 ]; factors = [ 4, 2, 1 ]; affreg = AffineRegistration ( metric = metric, level_iters = level_iters, sigmas = sigmas, factors = factors ); # give slightly more degrees of freedom, by allowing translation of centre of gravity print ( '\nTranslation only:' ); transform = TranslationTransform3D(); params0 = None; translation = affreg.optimize ( static, moving, transform, params0, static_affine, moving_affine, starting_affine = c_of_mass.affine ); # refine further by allowing all rigid transforms (rotations/translations around the centre of gravity) print ( 'Rigid transform:' ); transform = RigidTransform3D(); params0 = None; rigid = affreg.optimize ( static, moving, transform, params0, static_affine, moving_affine, starting_affine = translation.affine ); # refine to a full affine transform by adding scaling and shearing print ( 'Affine transform:' ); transform = AffineTransform3D(); params0 = None; affine = affreg.optimize(static, moving, transform, params0, static_affine, moving_affine, starting_affine = rigid.affine ); # transform the MRI and resample in MNI space resampled = affine.transform ( moving ); save_nifti ( new_gmfilename, resampled, static_affine ); When I look at the resampled image together with the template, then it is quite obviously not the optimal affine transform: position and scalings are visibly off. Is it because of how I apply affine.transform and static_affine in the last two lines? Should I use a different metric for T1-weighted images? Or am I doing something else wrong?
participants (1)
-
a.m.wink@gmail.com