Bad initial affine for mrregister


I try to register my fod to an existing template, and it works for most of the subject except a few ones, where the result is totally wrong
I suspect this is due to a bad initial rigid (or affine) registration, which may happen when the initial volume is a bit to far away from the template

I try to test

-rigid_init_rotation search

-rigid_init_rotation moments

without sucess. The I use the fa to compute a linear registration (to a fa template)

mrregister fa.nii.gz template_fod_final_FA.nii.gz -type affine -affine mrt_aff.txt

If I reslice the fa with the produce mrt_aff.txt the result looks well alligned to the template space, and I then try

mrregister wm_fod.nii template_fod.nii -affine_init_matrix mrt_aff.txt

but it does not help (I get almost the same as without the -affinie_inti_matrix argument)

Any idea I could test ?

Many thanks


It seems that results diverge even after reasonable initialisation.

Are you using masks? If not, I’d try with.
Are FODs and template normalised (intensity values in the first volume approximately in the same range)?
Do image and template roughly share the same pose? If not adjust the pose with the “transform” tool in mrview: mrview wm_fod.nii -overlay.load template_fod.nii -overlay.opacity 0.2 and save the modified wm_fod for subsequent registration.

If you want to visualise what mrregister is doing, you can write the transformed images at each resolution stage with -linstage.diagnostics.prefix. For instance, status at initialisation (without optimisation) followed by each resolution stage (assuming default parameters):

mrregister wm_fod.nii template_fod.nii -type affine -affine_niter 0,500,500,500 -affine_scale 0.25,0.25,0.5,1 -affine_lmax 0,0,2,4 -linstage.diagnostics.prefix /tmp/diag  -affine_init_matrix mrt_aff.txt -info
mrview /tmp/diag*.mif

Thanks for your quick response,

I am not sure to understand, " sharing the same pose "
do you mean both volume roughtly coregistered ?

Well no it looks like that (in color over is the template)
Screenshot from 2021-08-26 18-05-01

But the init affine is indeed correcting this difference in position

so why to do a manual correction ?

With the diagnostic the mismatch is there at the first stage
diag_stage-1_iter-1.mif (not sure but in green is the template ?)
Screenshot from 2021-08-26 18-09-18

it seems to me that the initial affine is not taken into account

I dig a little more further and find out a solution :slight_smile:

In my case, adding the argument “-type nonlinear” to the mrregister of the fod make the job,

So to resume, I first use fa to compute
the affine, doing an affine registration of fa, to fa_template
and then use this affine to no-linearly register fod to fod template

mrregister fa.nii template_FA.nii -type affine -affine aff_fa_2_fa_template.txt

mrregister ./wmfod_norm.mif ./template_fod.nii.gz -info -type nonlinear -affine_init_matrix aff_fa_2_fa_template.txt -transformed res_ok.nii

I do not know why but the affine registration is bad when perform with fod, but it works much better when FA is used as input. (and as target), that is why I need this 2 steps

This being said, I do not fully understand, the mrregister argument. for instance if I omit the affine_init_matrix argument, I do have a decent result, which I do not understand given the initial mismatch in position …

is there still an affine registration done even with -type nonlinear ?

As far as I know, initialisation works but if linear registration diverges then that might undo the initialisation depending on the exact command you used. If you set the number of iterations to zero in the first stage then you’ll see the effect of the initialisation in the first diagnostics image. The -info option should give you an idea of what operations preceeded each diagnostics image.

Yes, images need to share roughly the same pose up to a translation. If images are rotated by let’s say more than 45 degrees, registration might not find a good solution as it requires a sensible starting point.

The default is centre of mass initialisation which should take care of the shift between images.

Red is image1 (“moving”), green is image 2 (“template”).

No, -type nonlinear only performs nonlinear registration (but one can initialise the linear transformation).

I’ve created an example demonstrating the effect of the initialisation method which is probably a good starting point for figuring out what’s going on:

Performing the registration in two steps using different contrast is conceptually OK. Yet, if linear registration using the FODs fails I’d be concerned that the nonlinear registration yields suboptimal results. Comapred to FODs, FA removes local and global scaling and directionality. I’d double-check that FODs’ first volumes are roughly in the range [0 0.28] and have a look at the ODFs in mrview to make sure directions are OK.