Mrregister

Dear experts
I am trying to make use of mrregister command to register T1 (not cropped nor brain extracted but rigidly aligned with the DWIs) to MNI template.
Please find attached

what I have provided to the command. The execution has been in this stage for more than one hour.
Is this expected? Did I do something wrong?

Cheers,
Hamed

Hello Hamed,

The time the command takes depends on how big the dataset is. You can speed it up substantially if you use masks. Can you post what dimensions mrinfo reports on your T1 files?

I suspect though that there is something wrong, as the linear registration typically takes less than a minute on unmasked anatomical images on my machine. Did you run out of memory on your machine?

You can run mrregister with the -debug option to monitor its progress. I can have a look what is going on if you put reg_analyse_descent: 1 into the file .mrtrix.conf in your home folder (create it if it doesn’t exist). This allows you to write the gradient descent progress to file via:

mrregister anat1.mif anat2.mif -type affine > gd.csv

Also note that you are not creating any output transformation or transformed files with the command in the screenshot.

Cheers,
Max

Dear Max

Sorry to reply a bit late.

I am trying to register my subject’s anatomy to MNI space. Then I can use the inverse transform to bring my masks to the subject space (or normalize tracts, etc).
First of all I was wondering if I took the right command/settings for this job.

mrregister manat_coreg_dwi_mc_epi_bias_Gibbs.nii MNI152_T1_1mm.nii.gz -type affine -transformed manatcoreg_inMNI.mif -affine manat_affine_MNI -debug

I am using Ubuntu and here is the information regarding the images:

Image1:  "manat_coreg_dwi_mc_epi_bias_Gibbs.nii"
************************************************
  Dimensions:      160 x 240 x 256
  Voxel size:        1.1 x 1 x 1
  Data strides:      [ -1 2 3 ]
  Format:            NIfTI-1.1
  Data type:         32 bit float (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:        0.9997     0.01064     0.02259      -92.25
                         -0.01038      0.9999    -0.01169      -93.79
                         -0.02271     0.01145      0.9997      -141.9
  comments:          Bias corrected
Image2:               "MNI152_T1_1mm.nii.gz"
************************************************
  Dimensions:      182 x 218 x 182
  Voxel size:        1 x 1 x 1
  Data strides:      [ -1 2 3 ]
  Format:            NIfTI-1.1 (GZip compressed)
  Data type:         signed 16 bit integer (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:              1           0           0         -91
                               -0           1           0        -126
                               -0           0           1         -72
  comments:          FSL5.0

Here is the last couple of things the command was doing (it took long so I stopped it):

mrregister: [INFO] loop density: 1
mrregister: [DEBUG] neighbourhood kernel extent: [ 1 1 1 ]
mrregister: [DEBUG] coherence length: 8.0743012065510626
3.7154015415763357
0.74035117220249147
mrregister: [DEBUG] stop length:      0.00053828673350513707
0.00024769342984782655
4.935674356664318e-05
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 1, cost: 97.099110051955577
mrregister: [DEBUG]   x: -0.50544837501193218 -1.7535874486843053 0.6494528346796713 294.09821279789321 0.060337630083793649 -0.14124073646941693 1.3084735199980506 -67.404968515905921 -0.23985198648660983 -0.809302978091061 0.25390165860918751 42.883121741979437
mrregister: [DEBUG]   gradient: -876.07815463132113 -74.190149207846446 953.94934605602441 -16.03251984795973 23.821296560597297 2.0172921066600571 -25.938679278849794 0.43593760201980153 -1185.1514704457052 -100.36383621877607 1290.4949909232637 -21.688663702333248
mrregister: [DEBUG]   norm(gradient): 2182.8977676034406
mrregister: [DEBUG] step size changed from 0.00015497929198230617 to 3.0269392965294173e-07
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 2, cost: 320.70313446089187
mrregister: [DEBUG]   x: -0.50533303356512249 -1.753625607682664 0.64934353122195554 294.11238981413919 0.060276740566137951 -0.14145613138522303 1.3085933018399341 -67.346324473335784 -0.23967603057859999 -0.809302527639578 0.25371323819516678 42.8870566118227
mrregister: [DEBUG]   gradient: -3230.3758172618318 -148.60400642824723 3053.10360409135 -53.695314287983635 -4112.5309628916066 -264.14704435871789 3885.3848096841084 -68.342570839632614 -1111.3710710010853 -75.879117762075396 1049.8992367670785 -18.467952708743965
mrregister: [DEBUG]   norm(gradient): 7362.6652140565948
mrregister: [DEBUG] Gradient descent iteration: init; cost: 320.70313446089187
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 3, cost: 320.01070833652705
mrregister: [DEBUG]   x: -0.50531032595099701 -1.7535913307467861 0.64931436803006748 294.10284372494709 0.060292607121608194 -0.14145946124501596 1.3085793620132384 -67.344027781088414 -0.23966704497556859 -0.80928638015361654 0.25370112425955188 42.882472494580362
mrregister: [DEBUG]   gradient: -3232.6842391487494 -148.5018026675057 3055.2894180652938 -53.733729162930857 -4098.663189818305 -263.14368066068818 3872.2851912016217 -68.112138329303207 -1109.6000681842613 -75.623697084311743 1048.2288184027784 -18.438552057785309
mrregister: [DEBUG]   norm(gradient): 7349.3912818454164
mrregister: [DEBUG] Gradient descent iteration: 1; cost: 320.01070833652705
mrregister: [DEBUG] step size changed from 0.046007490301206336 to 0.000718867035956349
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 4, cost: 235.94421118092217
mrregister: [DEBUG]   x: -0.50472237522275054 -1.7527047261821489 0.64856026983173731 293.85612991072003 0.060702812664551624 -0.14154594114130367 1.3082191369804388 -67.284521037344376 -0.23943466510750352 -0.80886871193568255 0.25338806402656472 42.76394743743041
mrregister: [DEBUG]   gradient: -2489.4482883603073 -85.266059713295576 2353.4071052535301 -41.385831173731518 -1088.222674323041 -37.272700125579391 1028.7544376094208 -18.091157020427179 -271.99013772882893 -9.3159305350701125 257.126659622852 -4.5216998375087742
mrregister: [DEBUG]   norm(gradient): 3758.9016592389594
mrregister: [DEBUG] Gradient descent iteration: 2; cost: 235.94421118092217
mrregister: [DEBUG] step size changed from 0.0052468537127004231 to 0.0013117134281751058
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 5, cost: 95.803792953459237
mrregister: [DEBUG]   x: -0.50408029370554519 -1.7521048549629477 0.64785101947784063 293.70482724486692 0.060899881583922781 -0.14160748596041167 1.3080438644614825 -67.25173704848784 -0.23930486926061911 -0.80859207519298004 0.25321223124112407 42.682102125417998
mrregister: [DEBUG]   gradient: -846.85095433461026 -71.715061409483184 922.1242532116205 -15.49765242045892 24.673155948694234 2.0894313042566606 -26.866257146087833 0.45152691043382359 -1289.4339815291146 -109.19493766349007 1404.0467702105379 -23.597068129382826
mrregister: [DEBUG]   norm(gradient): 2284.8754268396292
mrregister: [DEBUG] Gradient descent iteration: 3; cost: 95.803792953459237
mrregister: [DEBUG] step size changed from 0.0047162388525927076 to 0.00058952985657408845
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 6, cost: 94.099958543260755
mrregister: [DEBUG]   x: -0.50401663823427423 -1.7521338323518445 0.64779230100169471 293.72176521997307 0.06086137912678187 -0.14174377240938321 1.3081198202001043 -67.205332409553918 -0.23919363335701041 -0.80859365840771869 0.25309371679766629 42.692867364357724
mrregister: [DEBUG]   gradient: -894.97667349142205 -75.790558859229918 974.52768100561286 -16.378368990664487 25.181051509308819 2.1324421329422085 -27.419297574446574 0.46082156709567212 -1284.6019028288324 -108.78573599824726 1398.7851867640643 -23.508639491755424
mrregister: [DEBUG]   norm(gradient): 2318.896205045186
mrregister: [DEBUG] Gradient descent iteration: 4; cost: 94.099958543260755
mrregister: [DEBUG] step size changed from 0.057099765821561281 to 0.00089218384096189502
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 7, cost: 2139.8592524253318
mrregister: [DEBUG]   x: -0.50391427134754196 -1.7521740171791942 0.647697308771639 293.74693037557546 0.060803416779153713 -0.1419496622945158 1.3082340679504831 -67.135281261161921 -0.2390253612074506 -0.80859464892269151 0.25291389044459933 42.708590088029098
mrregister: [DEBUG]   gradient: 207061.37007019867 7057.545149510549 -195746.73631678629 3442.2989220999966 -1913.1503054259033 -183.42808326744122 1806.2992169884203 -31.780113644761308 -128.31776146804168 -37.22889048687162 120.66422795407296 -2.1262418208001144
mrregister: [DEBUG]   norm(gradient): 285061.12336134596
mrregister: [DEBUG] Gradient descent iteration: 5; cost: 2139.8592524253318
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...
mrregister: [DEBUG] threads "loop threads" completed OK
mrregister: [DEBUG] Metric evaluate iteration: 8, cost: 117834.30361055202
mrregister: [DEBUG]   x: -0.50472820073497504 -1.7525286780611247 0.64857319928582391 293.81792399838628 0.060832540597392126 -0.14190736496780718 1.3081861385252971 -67.149680570358143 -0.23906663309231008 -0.80875156928846137 0.25298075962031735 42.756810483722454
mrregister: [DEBUG]   gradient: -154053.76004019252 -5183.4721779568845 145881.26304320808 -2563.9371678106922 1960742.426088182 66968.516252504254 -1853553.1423225224 32595.887110356936 -29800.564098684099 -1027.1537783237209 28191.353206155312 -495.64483695236459
mrregister: [DEBUG]   norm(gradient): 2707849.4898486407
mrregister: [DEBUG] Gradient descent iteration: 6; cost: 117834.30361055202
mrregister: [DEBUG] initialising threads...
mrregister: [DEBUG] launching 1 threads "loop threads"...
mrregister: [DEBUG] waiting for completion of threads "loop threads"...

Cheers,
Hamed

It’s possible that your image and the MNI template are not in the same intensity range. Unfortunately we don’t get have a cross correlation or MI metric, however this is something that will be added at some point (@maxpietsch FYI Nick has kindly agreed to write a MI metric and has started work on it).

If this is the issue, you could manually scale one of your images using mrcalc to ensure the intensity range is the same.

I’ve been thinking it might be nice to add a histogram normalisation option to mrregister (like ANTS). @rsmith did you still have code lying around to do this?

@rsmith did you still have code lying around to do this?

Yes it’s on the list. Only yesterday started porting my own code base over to 0.3.13 :neutral_face:

Thanks Dave

I was wondering if the following (temporary) procedure for transforming the masks (using TBSS output) is correct, until it is fully implemented in MRtrix.

invwarp --ref=subj_fa_FA.nii.gz --warp=subj_fa_FA_to_target_warp.nii.gz --out=MNI_2_subj_warp.nii.gz

applywarp --ref=subj_fa_FA.nii.gz --in=ROI_in_MNI.nii.gz --warp=MNI_2_subj_warp.nii.gz --out=subj_ROI.nii.gz --interp=nn

Cheers,
H

Your computer seems to have only one core as mrregister runs on 1 thread. Are you using a virtual machine? If so, make sure that you are not running out of RAM (you can check your free memory and swap via free -m before and while mrregister is running)! Each metric evaluate iteration should take on the order of a second at full resolution.

I’ve had a look at your debug output. I think the registration failed at an earlier resolution level than you posted here. I would start with

release/bin/mrregister manat_coreg_dwi_mc_epi_bias_Gibbs.nii MNI152_T1_1mm.nii.gz -type affine -affine_scale 0.3 -affine_niter 0 -transformed_midway - - -info -affine_metric.diff.estimator lp -affine_init_translation mass -affine_init_rotation search | mrview - -

and to see if that is a good starting point for registration. If not, have a look at the advanced options in mrregister. Then I would use something like

release/bin/mrregister manat_coreg_dwi_mc_epi_bias_Gibbs.nii MNI152_T1_1mm.nii.gz -type affine -affine_scale 0.3 -affine_niter 10 -transformed_midway - - -info -affine_metric.diff.estimator lp -affine_init_translation mass -affine_init_rotation search | mrview - -

to see whether registration works for at least 10 iterations. If not, you could start with rigid registration followed by affine registration (-affine_init_matrix …), change image scale factors (start lower?), normalise image intensities or use image masks.

Hope that helps!

Great to hear!

I think a separate command would make more sense as there is already a myriad of options in mrregister and it would be useful to first look at the preprocessed images before registering them.

Cheers,
Max