Error in population template

Hello,

I try to perform the fixel analysis with population_template script and I get the error

Command: mrmath input_transformed/* mean initial_template.mif
mrmath: [ERROR] mrmath requires either multiple input images, or the -axis option to be provided
population_template: [ERROR] Command failed: mrmath input_transformed/* mean initial_template.mif
population_template: Changing back to original directory (/export/dataCENIR/users/audrey.fayard/Sujets)
population_template: Contents of temporary directory kept, location: /tmp/population_template-tmp-6YK9D4/

it performs the linear registration and 2 mraverageheader
then the mrtransform for all the volumes

and it fail making the mean

The strange thinks is that the command is running ok outside the script :
if I go in the tmp dir and type
mrmath input_transformed/* mean initial_template.mif
it works …

so my first guess would to say that the script is not running the command from the right dir …

I can rerun it with the -continue option

Many thanks

romain

Sorry for the question

I just see that there were update of the script,
and it seems to work nows

Yep; one step ahead of you :sunglasses:

This has to do with how individual constituent commands are executed within the Python scrips. Previously, the script essentially invoked a new shell every time a new command was executed, and passed the text string for that command to the shell. This is not ideal, and can even be insecure if someone is malicious enough. The new design spawns each command as a process, so doesn’t require a shell interpreter.

The catch for anyone using the scripts library for their own development is that wildcard characters can no longer be used. However this is relatively easy to get around: either track the filenames of interest in a list, or query the directory contents directly, and merge them manually into the command string; e.g. using:
' '.join(list)

Rob

Yes you are updating to quickly !

I keep the same thread to report an other error

the affine registration works for a few subjects, but I get an error for one

Command: mrregister upsampled_mbc_FOD_NP_HP_2010_015_VS.nii initial_template.mif -force -mask1 upsampled_mbc_FOD_NP_HP_2010_015_VS.nii -mask2 initial_template_mask.mif -affine_scale 0.3 -affine_lmax 0 -type affine -datatype float32 -affine linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt

mrregister: [ERROR] registration failed: encountered NaN in parameters.

I do not see any obvious difference with this subject.
what should I check ?
any idea where this could come from ?

Many thanks

Hello Romain,

This error usually means that the registration has failed due to non-overlapping images.

A guess to why that happens is that you are using the images as masks which might confuse mrregister. Either use no masks or better use dwi2mask to create masks for each of the input images and rerun population_template with the correct masks folder.

Cheers,
Max

thanks for your quick reply

well, no

The command I use was :
population_template /xxx/upsampled_FOD -mask_dir /xxx/upsampled_mask FOD_template.nii -nocleanup -nthreads 20 -force -tempdir /dataloc/tmp/

the mask_dir contain binary mask (and not the fod) created by dwi2mask
some of them have some holl but there should be enough brain to perform the registration
I will redo the mask with bet2 (because you can control the threshold and you can get mask with no holl)

if I run the mrregister command without the -mask2 option (no mask on template) then it works …
so there may be a mismatch between the 2 mask ?

but the problem is that this -mask2 option is automaticaly generated by the population_template script

if I look at the file produce by the population_template script
initial_template.mif (looks blurry but it is ok since it is the first iteration)
initial_template_mask.mif (contains a lot of holle) may be because it is the intersection of all single subject mask. but here again there is enough brain to perform the registration …

if it is just a problem of computation time, I’ll first try to re-run population_template without the -mask_dir option

but I can test other suggestions

Many thanks

romain

In the script output you provide, the fist image and the mask for it are the same:
upsampled_mbc_FOD_NP_HP_2010_015_VS.nii

Can you report what
find /dataloc/tmp/

and

for f in /xxx/upsampled_mask/*; do echo $f; mrstats "$f"; done
give you?

Also could you add
print ("\n".join(["%s"]*6) % (inputDir, input[0].filename, abspath(input[0].directory, input[0].filename), maskDir, input[0].mask_filename, abspath(input[0].mask_directory, input[0].mask_filename))); sys.exit()
to line 103 in population_template and report its output?

sorry I remove the absolute path from the script output :blush:
same name but diferent path

the mask looks good, although the matrix size is different (I mix 2 group of acquisitions),
but it should not be a problem …

for f in upsampled_mask/*; do echo $f; mrstats “$f”; done
upsampled_mask/upsampled_mbc_FOD_N_21.nii
volume mean median std. dev. min max count
[ 0 ] 0.171012 0 0.37652 0 1 7864320
upsampled_mask/upsampled_mbc_FOD_N_22.nii
volume mean median std. dev. min max count
[ 0 ] 0.1711 0 0.376597 0 1 7864320

…

upsampled_mask/upsampled_mbc_FOD_NP_GL_2012_088_VS_3T.nii
volume mean median std. dev. min max count
[ 0 ] 0.213135 0 0.409522 0 1 6582400

…
upsampled_mask/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii
volume mean median std. dev. min max count
[ 0 ] 0.215714 0 0.411317 0 1 6582400

Hi Romain,
I’ve just pushed another update to the population template script. I don’t think it will fix your issue, but it’s related to masking so you never know.

Basically I’ve remove the template mask that is used for the affine template building. This mask was computed from the intersection of all transformed input masks. The idea was to remove any spurious non-brain tissue (sometimes found in the output from dwi2mask) from the metric calculation, since these regions would not be consistent across subjects. However, in practice the intersection mask was too small and did not cover the outside of the brain. And therefore important template brain edge information was not being used in the alignment. I’ve tested this and the affine template is sharper now.

Note I’ve still kept the template mask for the non-linear template building step, since this is where I observed the issue in the first place. However now I perform a median filter followed by some dilation to ensure the mask covers the whole template brain.
Cheers,
Dave

Romain,
Sorry, when skimming the thread this morning I missed one of your previous comments. Looks like the changes I made today (to remove -mask2 template_mask for affine registration and remove holes in the non-linear registration) will fix your issue.

Also, in the unlikely chance that you have already updated today, you may want to update again. Since I introduced a bug in the first commit.

Let us know if you have any more issues.
Cheers,
Dave

Hi Romain,
Sorry, I’ve just pushed another worthy update to the population template script. Turns out using only the first FOD SH coefficient for low multi-resolution levels is a bad idea. The registration of some subjects can get off to a bad start if the global intensity normalisation is not perfect, and when there is little contrast in the FOD DC term (e.g. when not performing multi-tissue CSD).

Thanks for working with us on these issues. The registration tools in MRtrix are still in their infancy, however the good news is we are using them for several studies and therefore we are also discovering issues, which can be ironed out straight away.

Cheers,
Dave

Hi,

thanks for making the changes, and no problem for the multi push, I am happy to test.
I just re-run it.
I 'll keep you inform how it goes,

One process is still running (without the -mask_dir option); the linear_template9.mif already looks good.

So if both works, I will be able to compare the influence of mask. But only in a few days … it is very demanding in term of cpu and memory

is there a plan to make the script cluster compliant ?

Just an “off subject” question. I am just curious why did you develop mrregister and did not base your scripts with ants ?

Many thanks

Romain

Yes, Richard Daws from Imperial has offered to take a look at this. And if not, it’s something that I’d be happy to add when I have time. It’s reasonably trivial if anyone else wants to try in the mean time. The registrations from all subjects can be run simultaneously, then the script would need to keep checking the output directory until all output is saved, before re-averaging to create the template and starting the next level.

Our old (unreleased) FOD registration code was a modified version of ANTS. However we decided to implement a standalone version in MRtrix for several reasons:

  • We would like to have all fixel-based analysis tools in MRtrix, and not expect users to download and install several packages (which may or may not be cross-platform).
  • mrregister is similar to ANTS in kind (registration to a midway space, same metric and regularisation), however substantially faster (days instead of weeks to build a FOD template).
  • We can reuse the highly optimised spherical harmonics code in MRtrix for FOD reorientation.
  • Multi-threading in MRtrix is more flexible, and much easier to write and maintain (than ITK)
  • In MRtrix is easy to modify the image strides and optimise the data layout in memory for CPU caching of FOD data.
  • In ANTS you cannot initialise non-linear registration with warps from a previous registration. So the registration at each template level must start from the identity warp (and therefore takes much longer).
  • It’s nice to be able to use mrregister and mrtransform in MRtrix pipes to build up more complex tools.
  • For future projects that are registration related, it will be easier to start off with the current known code base.
  • In terms of maintaining a FOD registration in ANTS. The ANTS code is reasonably large, not always optimised or clearly organised, and is interwoven with code for features we are not interested in (e.g. cortical thickness estimation, point set registration).
  • The consistent interface for all MRtrix commands makes it easier for users to read the help, use commands, and more robust.

All that said, the ANTs registration is quite robust and served us well in the past. It might take us a little while before we are as happy with mrregister. We also won’t benefit from future improvements to ANTS, and have to spend time on maintenance and support!

Well yes it could be done quite simply if on think it totally independent : The way I see it is to produce a list of list of string. (if you can construct all the command without executing them) the first list tell you the cluster submission that need to wait previous item to be finish. Each list element is then a list of string telling you the command to submit. (it can be n job to submit in paralel or one job that make the average. then there is just a need to convert this list of list into job files and a script to do the submission (this will depend on the specific cluster manager) and it is generic to be used by any scipt. (I have something similar in matlab that I could try to translate to python … I personaly interested in a slurm submission )
but may be there is an other place to discuss about it …

I’ll come back later to my initial bug, it seems not resolved …

About the error

I rerun the new population_template script and get the same error for the same subject.

output error details

…
Command: mrregister /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_FOD/upsampled_mbc_FOD_N_38.nii linear_template0.mif -force -affine_init_matrix linear_transforms/upsampled_mbc_FOD_N_38.txt -mask1 /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_mask/upsampled_mbc_FOD_N_38.nii -affine_scale 0.4 -affine_lmax 0 -type affine -datatype float32 -affine linear_transforms/upsampled_mbc_FOD_N_38.txt
Command: mrregister /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_FOD/upsampled_mbc_FOD_N_37.nii linear_template0.mif -force -affine_init_matrix linear_transforms/upsampled_mbc_FOD_N_37.txt -mask1 /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_mask/upsampled_mbc_FOD_N_37.nii -affine_scale 0.4 -affine_lmax 0 -type affine -datatype float32 -affine linear_transforms/upsampled_mbc_FOD_N_37.txt
Command: mrregister /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_FOD/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii linear_template0.mif -force -affine_init_matrix linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt -mask1 /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_mask/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii -affine_scale 0.4 -affine_lmax 0 -type affine -datatype float32 -affine linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt
mrregister: [ERROR] registration failed: encountered NaN in parameters.
population_template: [ERROR] Command failed: mrregister /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_FOD/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii linear_template0.mif -force -affine_init_matrix linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt -mask1 /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_mask/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii -affine_scale 0.4 -affine_lmax 0 -type affine -datatype float32 -affine linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt

In the template dir I have

-rw-r–r-- 1 romain technos 27 juin 8 18:06 cwd.txt
-rw-r–r-- 1 romain technos 397 juin 8 18:06 command.txt
drwxr-xr-x 2 romain technos 4096 juin 8 19:35 linear_transforms
-rw-r–r-- 1 romain technos 3484 juin 8 19:35 average_header.mif.gz
drwxr-xr-x 2 romain technos 4096 juin 8 21:09 input_transformed
drwxr-xr-x 2 romain technos 4096 juin 8 21:10 masks_transformed
-rw-r–r-- 1 romain technos 4667149636 juin 8 23:04 initial_template.mif
-rw-r–r-- 1 romain technos 242 juin 8 23:43 linear_transform_average.txt
-rw-r–r-- 1 romain technos 242 juin 8 23:43 linear_transform_average_inv.txt
-rw-r–r-- 1 romain technos 4667149604 juin 9 01:29 linear_template0.mif
-rw-r–r-- 1 romain technos 3241588 juin 9 01:30 init_nl_template_mask.mif

I do not understand why this particular subject does not work. May it is due to the fact it has a different matrix dimention ?

I had a look at volumes in input_transformed subdir and a few volume have a very wrong image registration (on has a scale factor too small (volume appears very very smal) an other has a wrong orientation (sagital in the axial plane)

I look in the previous run (before the update) and it was not the case. I do not have the previous log to compare and see if the argument to mrtransfor have changed

Many thanks

1 Like

Hello Romain,

When you change line 214 in population_template
from
runCommand('rm -f input_transformed/' + i.prefix + '_translated.mif')
to
runCommand('mv input_transformed/' + i.prefix + '_translated.mif ' + i.prefix + '_input_translated.mif')
you can check the initial alignment of your input images when no rotation has been performed by flicking through all images in mrview:
mrview population_template-tmp-KJXBGO/*_input_translated.mif

This is the starting point for the initial template.

If there are huge rotations in your input images, mrregister will struggle with default parameters. If the initial alignment looks acceptable to you, then we need to find out what is going wrong with the registration. What is the content of linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt?
To see what is going on during linear registration, you could add reg_analyse_descent: 1 to ~/.mrtrix.conf and rerun the failed command with its output saved to file:
mrregister /export/dataCENIR/users/audrey.fayard/Sujets/upsampled_FOD/upsampled_mbc_FOD_NP_HP_2010_015_VS.nii linear_template0.mif -force -affine_init_matrix ... > gd.csv

If there are larger rotations between your input data you could try to align them roughly before building the template with
mrregister -rigid_init_translation mass -rigid_init_rotation search problem.mif initial_template.mif -type affine -transformed problem_fixed.mif.
This performs a brute force search with rotations of up to 20 degrees with both images aligned by their (masked if provided) centres of mass. If you expect larger rotation angles, define them via -init_rotation.search.angles 2,5,10,15,20,25,30 or try the option -init_rotation.search.run_global. For more options see mrregister's “Advanced linear transformation initialisation options” group.

Cheers,
Max

Hi Max,

thanks for trying to understand.

So I modify the population_template
and look at population_template-tmp-KJXBGO/*_input_translated.mif : they look find. It is a very coarse alignment (with still 5 to 15° angle mismatch)
If I compare the original file, they are much more dispersed with more translation shift.
So for me the first mrregister, works ok (and the template initial_template.mif)

If now I look at input_transformed/*mif, then some volumes are very wrong (as debribe before) so I guess this is the second mrregister path that go wrong (although it ended without error and produce the file initial_template0.mif)

cat linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt
4.270709839275504960e-02 -2.943247272939077952e-01 4.575290134430459732e-01 1.760120548707697452e+01
5.014655345191898483e-01 1.983182897681324552e-01 1.664026731600164177e-01 -1.157127937245216032e+01
-4.450650865711688886e-01 3.363660879928020431e-01 2.645908441227464158e-01 4.260960361647686767e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00

then the thrid mrregister get an error for the subject 015_VS (its input_transformed has a 90 ° tilt wrong)

the out for gd.csv

not sure if this is the best way to share
it was to big to publish so I put only the firsts and the lasts lines

#iteration,feval,cost,stepsize,x_1,x_2,x_3,x_4,x_5,x_6,x_7,x_8,x_9,x_10,x_11,x_12,g_1,g_2,g_3,g_4,g_5,g_6,g_7,g_8,g_9,g_10,g_11,g_12
0,1,1968.250910537191,0.0009290824116225645,0.04270709839275505,-0.2943247272939078,0.45752901344304597,17.601205487076975,0.50146553451918985,0.19831828976813246,0.16640267316001642,-11.57127937245216,-0.44506508657116889,0.33636608799280204,0.26459084412274642,4.2609603616476868,-419.78181259552474,210.18943571939312,-119.24933762954261,-2.6644907988680462,-220.38440211791709,-698.17727502288892,-104.48333484675321,2.7430378853199033,174.11523742814242,-216.41089409225751,-547.50013421360745,-3.5792162090188975
0,2,1906.3599076072296,0.00012965899733938653,0.047234121461950218,-0.29648150901318848,0.45939301868622129,17.601713329643449,0.50490129341339218,0.21075630947528406,0.17112142050678072,-11.502873613008262,-0.44586103265329935,0.34325127214098167,0.27481431709592513,4.1409003801324253,-0.12559499956204553,0.060039170724714111,-0.034293567102684323,-2.4987033050772238,-0.063224737104974935,-0.20512376076895142,-0.031670541203372995,2.930925927716264,0.049400577947889268,-0.064227696916140081,-0.16109531713593894,-3.423941114307095
1,3,1906.2885112248243,0.00012965899733938653,0.047239122700994715,-0.29648371145952845,0.45939498576682003,17.602044004553001,0.50490489374880965,0.21076976883563875,0.17112669110590512,-11.502909962187172,-0.4458617751587316,0.34325881192579721,0.27482531895166068,4.1409163453243156,-418.65143081849857,200.14846697381861,-114.31342354804865,-2.4992324793611935,-210.72304916533741,-684.05114279093016,-105.62449070995139,2.9338671377613754,164.62442262532855,-214.05079498286733,-536.91794781943975,-3.4229093350629416
2,4,1847.3397659776331,0.10550009723152279,0.051260001558601317,-0.29828114985384163,0.46102945593869393,17.870789398347661,0.50788451933176637,0.22161941826483805,0.17540824464793212,-11.531180757226686,-0.44647045370361749,0.3494264930396388,0.28376001407839085,4.1520304921173636,-413.79777115909474,184.81822928869769,-109.27709337714241,-2.3375466402291472,-203.08449743507828,-663.44348203955769,-110.2212915144983,3.0268150144711017,159.42101752993466,-212.8294513002287,-518.77598106923415,-3.1573659797025471
3,5,1738.7764905391693,0.83469288494318672,0.05915227505621358,-0.30147171678687557,0.4642281199343527,18.37581412308851,0.51383653479442915,0.24240954399801701,0.18414089350414986,-11.613128823614792,-0.44768466760868036,0.36180146053994316,0.30093579406766091,4.142675174228776,-405.15390824858827,155.05258156109176,-99.279589321302183,-2.0922402839474898,-191.2681706126225,-624.14703024868891,-114.72227507515933,3.0357413397074149,147.87954259071722,-214.13056025315896,-482.79311016372282,-2.5872181169570108
4,6,1644.3881178643637,0.82564633412203159,0.067079609682256056,-0.30389001097449242,0.46720303899295468,18.824060475961815,0.51977708935134204,0.26206934287663475,0.19317038835728984,-11.726679626319655,-0.44879771944892816,0.37430903453392805,0.31700275695085844,4.073734525273637,-388.37788630139676,125.24236004343192,-88.20826590147577,-1.697060798365257,-186.13338195013549,-571.18078452813029,-116.15396584913566,2.8585882596995713,137.10178267086383,-208.73293932491458,-432.08712571640353,-1.8833427403803058
5,7,1588.3704179272961,0.56673695777151345,0.072551399586704896,-0.30505573139116254,0.46899807654041281,19.074101169447701,0.52397195852114598,0.27464193798803682,0.1994694839887397,-11.819980724992515,-0.44954410381876686,0.38274473824473987,0.32705458092186923,3.9864061700370135,-375.83809119716778,104.19218898460534,-83.074500941605365,-1.4044765139559441,-185.30884587217571,-528.02822122302257,-112.87229814512079,2.5278039741257299,130.40056284933721,-201.87665472367704,-399.25277312352387,-1.4268163006379857
6,8,1515.1110523599148,0.44309712048049449,0.081005660650746533,-0.30629732561881201,0.4716821420794759,19.392705358506973,0.53076680235885998,0.29294523759614222,0.20927778014156317,-11.951184583251074,-0.45074249807762939,0.39560142587626468,0.34174000591619874,3.8192587115196028,-353.04470759341172,74.873759864082601,-71.856446174926901,-1.0539797989808311,-180.45950479793581,-435.67183203274681,-98.975292987648473,1.7405562633176175,118.39642759552044,-184.14609005820861,-336.67199384275534,-0.85251625978004475
7,9,1468.8557344423173,0.37076167227760742,0.088080301900097344,-0.30665400822067107,0.47362519492800115,19.571929638646761,0.53647369257165889,0.30571436799761165,0.21694685243065004,-12.001343659202778,-0.45185949120321012,0.40540062465935978,0.35217496596294107,3.6697592889682475,-332.93924919725976,51.91481663082309,-68.485653478541138,-0.80741013733943134,-173.6477908025407,-350.11414909828699,-80.168539513535848,0.90021227183074859,107.44954138329719,-157.41855199386598,-289.64534697958328,-0.54645706238172054
8,10,1420.7034433805909,0.25832289180513451,0.097707842336486536,-0.30639884033867176,0.47630584632517847,19.731342784010458,0.54417368293832213,0.32005455006346245,0.22661911788745176,-11.957415982581301,-0.45362312064811217,0.41721601706643835,0.36455277878422587,3.4918553183241143,-313.41037778793998,29.118967464289945,-63.045005760082816,-0.64899223642939297,-160.00544158326741,-256.23791923306476,-49.825026124565426,-0.079498497087990172,96.877864676033312,-124.8757735381797,-227.40772921317435,-0.20868901143375373
9,11,1388.0537620443915,0.23300816126674184,0.10633834356332282,-0.30555442547281264,0.47858974250483549,19.799183239497754,0.55067131851456819,0.32940850086034357,0.23379956946865982,-11.787197892280757,-0.45541684948990679,0.42574033363849961,0.37295040204763497,3.3584187978365918,-298.9516987934407,15.827244050212895,-58.217218349535436,-0.52290133072995049,-147.76271171005448,-201.58590480566357,-25.740043780616318,-0.61521680172227811,92.320923842496228,-92.990581737454704,-182.85308135544645,0.0074017544118179131
10,12,1347.060644894681,0.38454305013494555,0.12010786681452382,-0.30378796735680441,0.48209641874968368,19.835275858342488,0.56078920486329309,0.3412234051967995,0.24359346845132879,-11.393282226349243,-0.45871392480329021,0.43675535673935584,0.3834167751669616,3.1637985080145379,-276.28098372820421,-1.9216301818806598,-52.125221394434476,-0.27805367242967882,-127.01474423567058,-138.57123258814292,6.4443742411202862,-1.1589876932979499,84.288060602471802,-59.483848783741649,-122.31021656695589,0.063247644081456611
11,13,1316.8965955566464,0.73647835835071285,0.13275771134781006,-0.30161344574370741,0.48509529676973046,19.790285683500599,0.56955646413972127,0.34846883301178549,0.25012171569979363,-10.916329720071463,-0.46200787081303341,0.44381299069190316,0.38896083290268246,3.0584457152526165,-263.79528707710506,-6.369076285447643,-48.152628935498974,-0.20238919130357177,-113.15578412072712,-113.05234798530721,26.827515221029099,-1.3239289936782679,80.495191292458074,-31.227073508618567,-92.925015875727752,0.17622227945584976
12,14,1297.2999703841147,2.2897365476528497,0.14214054974878956,-0.30002867907876513,0.4872188924701098,19.736505711288757,0.57584235951450857,0.35268129274035592,0.25378592420468338,-10.525412368252463,-0.46463975026008164,0.44740652939647241,0.39147607682860036,2.9807418934509462,-255.15611679037366,-8.4253278978259072,-44.299730271762456,-0.16951307760427217,-105.22091259112608,-105.24644277316096,40.143941444067941,-1.3539052081758385,77.470271035611717,-14.981404816210457,-78.33379224252694,0.091851385429330829
365,367,979.74852815200563,1.0655304618275199,-0.90555576181430775,-0.19760932349320351,0.67959188455009356,6.5365425090779645,0.28354416978711566,-0.0041049518025179574,0.78635179698613833,-9.4535788459599459,-0.17357221991510238,0.74667490372419121,-0.2459415570007524,-1.6619539317135259,58.232003528068141,-92.649173454345544,119.9934769719665,1.4906673651341948,150.3755823074313,12.126880262042121,-28.579165788168808,-0.29784551654426178,-151.65930269592567,9.3014028328672502,18.215512058239309,0.49219956075979787
366,368,976.68720299123493,0.71502449224442233,-0.91995432236873054,-0.19083699172096369,0.67489550178260382,6.5457851155222482,0.27101237758584279,-0.0077906921037926499,0.79314046398599503,-9.5111282838907698,-0.15922621436602999,0.7495108466921121,-0.25362792473796297,-1.6870561434696132,62.170318064012662,-90.796014895826801,116.4706406900939,1.4912637216439728,153.43514692446772,10.227190810362103,-27.766388342906378,-0.34601801117806613,-151.97288480633131,10.42257682278051,11.515165747660523,0.47992925739285236
367,369,971.18501166674946,1.3901901325791379,-0.93437642199177784,-0.18415806344899505,0.67045320791464569,6.5606640780984353,0.25837803218319866,-0.01096260465190451,0.79953627899440738,-9.5532110564641748,-0.14482793168064334,0.75203452888674094,-0.26068621127585379,-1.7093793999412668,60.817356269595919,-85.630298207864186,109.24914121058808,1.5293172748840753,160.35520204778399,9.0880825378413554,-24.547878457175063,-0.31188778422421698,-147.93193277977866,6.1160942941989473,9.9341199431147817,0.46313759172878738
368,370,966.43478472329366,1.0545460088639018,-0.95579477888707765,-0.17436495002715854,0.66433000518219165,6.5905486851452206,0.23835866677808748,-0.01535617388808623,0.80893093892170898,-9.6193838350865839,-0.12231418611245276,0.75589388014663283,-0.2714163722854766,-1.7576535749621953,69.296907271582128,-78.569699804609257,109.88259342139108,1.5708960269552905,168.72769547962591,6.1412029746479302,-20.264769836110222,-0.29097585846331431,-163.98877157830435,13.466325517932681,9.8979663695284117,0.38510781107882985
369,371,961.33039628681536,1.0606224787471481,-0.97957540531810483,-0.16488301090495833,0.65879007901295372,6.6566451103345798,0.21593959164819912,-0.019527268691165431,0.81815319421835264,-9.653874476079956,-0.096781724558310953,0.75891773813812613,-0.28231122723837399,-1.8162304167064007,71.336301892303368,-79.348525788972182,94.78109844652127,1.5804370542812829,173.1467316482854,-0.79292817626036527,-20.893926331784076,-0.28117879298046028,-176.40491515942924,15.220496683507928,3.0404048937565129,0.32151480373626734
370,372,955.14204814515426,1.6082045613459661,-0.99835452653311019,-0.15798230536747249,0.65567173028877757,6.7312362896387459,0.19760275685060802,-0.021840992017532063,0.82534331163456498,-9.6598777254159032,-0.075692394384512834,0.76087642319171933,-0.29005657593657702,-1.8680374407710412,73.515522984114753,-73.123470954230356,93.574931011085738,1.5195490278271966,182.54105657641782,-2.1280713011071994,-16.187795029163638,-0.31145959469649309,-187.73562264978358,18.577332369121134,0.82762013878604568,0.36198961105546468
371,373,951.7150964323655,1.2351679977195789,-1.0133764729745836,-0.15288519235549014,0.65364848122770269,6.790069167870592,0.18235538100151763,-0.023466702779819909,0.83073729823629416,-9.6536157897557615,-0.058151141171829436,0.76205118834573227,-0.29604801674462827,-1.9193387317448116,86.199749102885107,-67.141620574433702,86.094751249897243,1.6317770868273553,197.00751535698063,-8.1061915533057949,-14.247836197376351,-0.27717280413421763,-195.70312605085641,20.961755178255693,-0.184544088673956,0.28028672791950404
372,374,948.46005711534076,0.58426993763130475,-1.0290668354631167,-0.14857946939165645,0.65276386246086049,6.864511344565611,0.16682526636831546,-0.024637108091498373,0.83574910334107944,-9.637988689636245,-0.040310435722020088,0.76299372007718225,-0.30181577806975607,-1.9745282514972977,91.52958181166926,-64.952067494279717,80.153269875608004,1.7343311948314379,208.42624771556612,-8.9929667657603503,-9.4565426109238118,-0.19193142003452918,-212.37611747957484,24.247620532693823,-2.3138385984734331,0.35177044904260479
373,375,946.94456579785492,0.65084751647048167,-1.0478860951741613,-0.14403966896658604,0.652650060200889,6.9550399532416591,0.1479561814011616,-0.025834408620362577,0.84140051673100824,-9.6332783356016378,-0.018533514741338526,0.76374778598177451,-0.30849157451987042,-2.0679120570953415,113.99686985454333,-59.427471851281773,75.653342611150009,1.6885645841495744,242.39280915358933,-13.193758584234669,-1.891956718624368,-0.26088127427336433,-241.80469158168793,32.493080436355932,-2.3359731585996029,0.34660601587404971
374,376,935.58126519209736,1.5997626875964832,-1.0763531832429341,-0.13917336255108947,0.65504361731443261,7.0968515402635539,0.12072009009109735,-0.027285956288311961,0.84867146434278851,-9.583761545361142,0.013013953476490855,0.76434706239542105,-0.31816931076807814,-2.2062411525482903,151.18328158325212,-54.564310890958595,58.465418809073391,1.6356769115126886,311.5310044020946,-24.127126727600778,7.538836752654146,-0.42186361470694417,-306.68397543003556,40.559164684054302,-9.2499248586512479,0.25310939453469189
375,377,0,1.0749394262347991,-nan,-nan,-nan,-nan,-nan,-nan,-nan,-nan,-nan,-nan,-nan,-nan,0,0,0,0,0,0,0,0,0,0,0,0

Many thanks

Romain

Hello Romain,

Your gd.csv is rather unspectacular. I think, the part where mayhem is happening is not included. For now, you could restrict the number of iterations per resolution level to 20 (-affine_niter 20) but I would like to understand why that is happening.

Any chance that you can share the two images, masks and linear_transforms/upsampled_mbc_FOD_NP_HP_2010_015_VS.txt with me? You can send them to me via email maximilian.pietsch@kcl.ac.uk if you prefer to not post a link here.

Cheers,
Max

ok, no problem to share (fod are just big). I send you 3 subject

So I just test it on 3 subject, and it does not reproduce the same bug,
but one see clearly that something goes wrong in the initial template !

Hello Romain,

I had a (long) look at your data. Sorry for the rather long-winded debugging but I never came across that problem with my data. The rigid registration worked fine for those images but I can reproduce that the affine transformation diverges slowly into high shear and scale factors for one of the images you sent me. I don’t know why the affine registration is performing so poorly on this image. The gradient descent gradients and steps seem reasonable taken for themselves but the image distorts nonetheless:

I have two possible solutions that I hope might solve your problem:

  • Could you rerun population_template with the input images not set to zero outside the mask?
  • If that does not help, you also try to rerun the population_template with the option -linear_lmax 6,6,6,6,6,6,6,6,6,6?

If that still does not work, could you check the branch registration_linear_tweaks out (git pull -a; git checkout registration_linear_tweaks; ./build) and rerun population_template with the additional options -linear_lmax 6,6,6,6,6,6,6,6,6,6 -nocleanup -verbose.
I would then be interested in the log folder located in your temporary output directory.

I really hope that this solves your problems as I am running out of options to try…

Cheers,
Max