2 Questions about mrview and mrregister


I’m a new user of MRtrix (I prefer mentioned it). I’m looking for a small feature that cannot find in mrview.
Here is my issue: I have two sample : imageA.mif (moved) and imageB.mif (ref)
I would like to registered A to B using a linear rigid tranform.
In order to do an initialisation of the tranform to apply, I used the transform tools of mrview to apply rotation and translation on my data and save it as “imageA_moved_manually_by_mrview.mif”.

  • How can save the applied transformation, I need it to apply it on other contrasts for instance and to use it in a script.
  • As an alternative, I tried to registered my initial image “imageA.mif” to the same image “imageA_moved_manually_by_mrview.mif” in order to get the corresponding transformation. But mrregister failed to registered the same image after applying the rigid motion in mrview. My data is slighlty different from usual input of MRtrix. Here, the hypothesis of intensity conservation is 100% true between the two volumes but the space to explore is large. In theory, it should be possible to get the correct minima. I’m sure I’m not using the optimal parameters, but I tried different options without success.

Thanks in advance for your help. I’m uploading the data and add a link in the forum today.


Hello Valéry,

This should do it:

transformcalc imageA_moved_manually_by_mrview.mif imageA.mif header R.txt
mrtransform another_image.mif -linear R.txt another_image_also_moved.mif

Registration might fail if the images have very different FOVs and no masks were supplied or if the images are heavily rotated against each other. You can initialise mrregister with -rigid_init_matrix R.txt (or its inverse depending on the order of the images).


Hello Max,

Thanks for the command,I have a look at the header using mrinfo and I tried to use transformcalc but unfortunately I’m not able to extract the correct transformation from the header using transformcalc .

The data and the basic command I used are available at this link. : https://filesender.renater.fr/?s=download&token=4a49118e-dcff-4909-bc1a-ea0080a0d0e4

There are mean_B0 images of rat ventricles.at 0.2 mm3 acquired on Bruker magnet. Bruker to Nifiti to mif was easy (using https://github.com/lamyj/dicomifier ). Tensor and fiber orientation (not shown) were perfectly displayed by mrview. I 'm working on template creation and I need to initialize the transformation to align them before rigid and then non linear registration as the data.
Thanks in advance for your help.

Hi all and Valery,

I was registering a b0 to another b0 and fractional anisotropy and mean diffusivity maps (generated from dwi.mif files using the dwi2tensor and tensor2metric commands). Note that the files were initially in .mif format but I converted to .nii as I thought the same format was of importance.

I tried using the mrregister -rigid command to register the files, but at the end I ended up performing this step in SPM: Coregister:Estimate&Reslice. Have you considered performing the step using SPM if nothing else works? Obviously, this is a different software but maybe someone on here can also provide help on this or theoretical advice? :slightly_smiling_face:

Take care,


You are right, there is a bug. All is good for translations and if the rotation is small (using the inverse transformation) but for large rotations where this feature is most useful our coordinate system handling gets in the way.

Before we release a fix,

transformcalc imageA.mif imageA_moved_manually_by_mrview.mif header R.txt -config RealignTransform false
mrtransform another_image.mif -linear R.txt another_image_also_moved.mif

does the trick. Also note that if you only want to use imageA_moved_manually_by_mrview.mif for registration, you can skip this step as as mrview applies the transformation to the header which is lossless as it does not cause image interpolation.

If mrregister does not work, (the images have relatively large intensity modulations compared to the anatomical contrast), you might have more success with other registration packages that support non-least-squares loss functions (See wiki). However, if you want to convert this pre-aligned .mif file to NIfTI for use in other software packages, I’d make sure that both images have the same strides (mrconvert -strides -1,2,3).



Thanks a lot, your command does the trick.
You are right, there are large intensity modulation in the images, for getting acceptable template , I need to remove manually by segmentation before the creation of the template as the intensity is really high. I’m not familiar with the concept of “strides”, I will have a look.
Any software recommendation to use l1 -loss functions instead of l2 in registration, I only know ANTs but I’m not sure if this option is available. Unfortunately I’m never tried SPM. Maybe I should.
Thanks a lot