# Error in population template

**URL:** https://community.mrtrix.org/t/error-in-population-template/276
**Category:** Uncategorized
**Tags:** registration
**Created:** [June 3, 2016, 3:22pm UTC](https://community.mrtrix.org/t/error-in-population-template/276 "2016-06-03T15:22:14Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 3, 2016, 3:22pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/1 "2016-06-03T15:22:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 3, 2016, 3:31pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/2 "2016-06-03T15:31:21Z")

</div>

Sorry for the question

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

---

<div class="post-metadata">

### Author: ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)
#### Post date: [June 6, 2016, 12:13am UTC](https://community.mrtrix.org/t/error-in-population-template/276/3 "2016-06-06T00:13:42Z")

</div>

Yep; one step ahead of you 🕶

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

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 7, 2016, 1:59pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/4 "2016-06-07T13:59:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)
#### Post date: [June 7, 2016, 2:37pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/5 "2016-06-07T14:37:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 7, 2016, 3:56pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/6 "2016-06-07T15:56:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)
#### Post date: [June 7, 2016, 4:33pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/7 "2016-06-07T16:33:15Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 7, 2016, 8:17pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/8 "2016-06-07T20:17:59Z")

</div>

sorry I remove the absolute path from the script output 😊  
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

---

<div class="post-metadata">

### Author: ![Dave](https://community.mrtrix.org/user_avatar/community.mrtrix.org/dave/32/7_2.png) [@Dave](https://community.mrtrix.org/u/Dave)
#### Post date: [June 8, 2016, 2:04am UTC](https://community.mrtrix.org/t/error-in-population-template/276/9 "2016-06-08T02:04:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dave](https://community.mrtrix.org/user_avatar/community.mrtrix.org/dave/32/7_2.png) [@Dave](https://community.mrtrix.org/u/Dave)
#### Post date: [June 8, 2016, 6:58am UTC](https://community.mrtrix.org/t/error-in-population-template/276/10 "2016-06-08T06:58:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dave](https://community.mrtrix.org/user_avatar/community.mrtrix.org/dave/32/7_2.png) [@Dave](https://community.mrtrix.org/u/Dave)
#### Post date: [June 8, 2016, 7:36am UTC](https://community.mrtrix.org/t/error-in-population-template/276/11 "2016-06-08T07:36:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 8, 2016, 10:27am UTC](https://community.mrtrix.org/t/error-in-population-template/276/12 "2016-06-08T10:27:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dave](https://community.mrtrix.org/user_avatar/community.mrtrix.org/dave/32/7_2.png) [@Dave](https://community.mrtrix.org/u/Dave)
#### Post date: [June 8, 2016, 12:47pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/13 "2016-06-08T12:47:51Z")

</div>

> [@Romain\_Valabregue](#):
>
> is there a plan to make the script cluster compliant ?

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.

> [@Romain\_Valabregue](#):
>
> Just an “off subject” question. I am just curious why did you develop mrregister and did not base your scripts with ants ?

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](http://www.ncbi.nlm.nih.gov/pubmed/22183751).
- 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](http://mrtrix.readthedocs.io/en/latest/getting_started/command_line.html#unix-pipelines) 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!

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 9, 2016, 10:24am UTC](https://community.mrtrix.org/t/error-in-population-template/276/14 "2016-06-09T10:24:09Z")

</div>

> [@about cluster submission](#):
>

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 …

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 9, 2016, 12:10pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/15 "2016-06-09T12:10:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)
#### Post date: [June 9, 2016, 1:48pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/16 "2016-06-09T13:48:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 10, 2016, 12:59pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/17 "2016-06-10T12:59:36Z")

</div>

Hi Max,

thanks for trying to understand.

> [@maxpietsch](#):
>
> mrview population\_template-tmp-KJXBGO/\*\_input\_translated.mif

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

---

<div class="post-metadata">

### Author: ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)
#### Post date: [June 10, 2016, 3:01pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/18 "2016-06-10T15:01:22Z")

</div>

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](mailto:maximilian.pietsch@kcl.ac.uk) if you prefer to not post a link here.

Cheers,  
Max

---

<div class="post-metadata">

### Author: ![Romain\_Valabregue](https://community.mrtrix.org/user_avatar/community.mrtrix.org/romain_valabregue/32/2691_2.png) [@Romain\_Valabregue](https://community.mrtrix.org/u/Romain_Valabregue)
#### Post date: [June 10, 2016, 6:58pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/19 "2016-06-10T18:58:30Z")

</div>

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 !

 ![](https://community.mrtrix.org/uploads/default/original/1X/87525e7183d475e2b48ecf50af3a7556ac7ac330.jpg)

---

<div class="post-metadata">

### Author: ![maxpietsch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/maxpietsch/32/25_2.png) [@maxpietsch](https://community.mrtrix.org/u/maxpietsch)
#### Post date: [June 14, 2016, 6:41pm UTC](https://community.mrtrix.org/t/error-in-population-template/276/20 "2016-06-14T18:41:25Z")

</div>

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:

 ![](https://community.mrtrix.org/uploads/default/original/1X/1b0366868c3046160dbccd4c43a9a3d20b203f7b.png)

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](https://github.com/MRtrix3/mrtrix3/tree/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

[Next page](https://community.mrtrix.org/t/error-in-population-template/276.md?page=2)
