Population_template error on linear transformation

Dear Experts,

I am trying to run population_template on my data which is consisting of CSD and it seems to error out doing the linear_transforms, but only once it gets to the sixth iteration and always the same participant. The data seems to be fine, and I don’t understand why it could go through five iterations of linear transformation with that participant without error. Any help would be greatly appreciated and please let me know what additional info I can provide.

Thank you in advance!
Ryan

population_template: Optimising template with linear registration (stage 7 of 12)... [===========================population_template: [WARNING] large scaling ([1.5033561096399, 0.96437798612909, 2.17591063875253]) in linear_transforms_6/01170.txt
population_template: [WARNING] large shear ([-0.0657805887928978, -0.749354551949378, -0.0510109745261085]) in linear_transforms_6/01170.txt
population_template: [WARNING] large scaling ([25.971895892697, 1.79162526802418, 14.3706421536904]) in linear_transforms_6/01170.txt
population_template: [WARNING] large shear ([-4.55398543579927, -18.2900798830257, 3.29183772435699]) in linear_transforms_6/01170.txt
population_template: [WARNING] you might want to manually repeat mrregister with different parameters and overwrite the transformation file: 
linear_transforms_6/01170.txt
press enter to continue population_templateTraceback (most recent call last):
  File "/usr/local/packages/mrtrix3/bin/population_template", line 621, in <module>
    check_linear_transformation(os.path.join('linear_transforms_%i' % level, '%s.txt' % i.prefix), command, pause_on_warn=do_pause_on_warn)
  File "/usr/local/packages/mrtrix3/bin/population_template", line 133, in check_linear_transformation
    return check_linear_transformation (transformation, newcmd, max_scaling, max_shear, max_rot, pause_on_warn = pause_on_warn)
  File "/usr/local/packages/mrtrix3/bin/population_template", line 138, in check_linear_transformation
    input("press enter to continue population_template")
EOFError: EOF when reading a line
----JOB [pop_template.sh.2323249] STOP [Thu Aug 27 10:40:46 EDT 2020]----

If you used default parameters, linear_transforms_6 should be the first affine registration, before that only rigid registrations were used. The previous registrations might have been poor as well but were not detected as the detection mechanism uses non-rigid properties (shear, scaling). While you could ignore this warning via the option -linear_no_pause, given the scaling and shear, the registration went completely wrong and would unlikely recover in subsequent steps.

For below, I am assuming you used intensity normalised Orientation Distribution Function (ODF) images as input and corresponding masks and the latest version of MRtrix3.

To debug population_template problems, it is best to go to the scratch directory of population_template (printed at the beginning of the output of the script) and have a look at its content. The file log.txt contains the commands that were run. Close to the end you should see mrregister and subsequent mrtransform calls that should guide you on what data to inspect. The folder content should look something like this:

β”œβ”€β”€ average_header.mif
β”œβ”€β”€ average_header_c0.mif
β”œβ”€β”€ command.txt
β”œβ”€β”€ cwd.txt
β”œβ”€β”€ initial_template_c0.mif
β”œβ”€β”€ input_transformed_c0
β”‚   β”œβ”€β”€ 0.mif
β”‚   β”œβ”€β”€ 1.mif
β”‚   └── 2.mif
β”œβ”€β”€ isfinite_c0
β”‚   β”œβ”€β”€ 0.mif
β”‚   β”œβ”€β”€ 1.mif
β”‚   └── 2.mif
β”œβ”€β”€ isfinite_c0.mif
β”œβ”€β”€ linear_template00_c0.mif
β”œβ”€β”€ linear_template01_c0.mif
β”œβ”€β”€ linear_template02_c0.mif
β”œβ”€β”€ linear_template03_c0.mif
β”œβ”€β”€ linear_template04_c0.mif
β”œβ”€β”€ linear_template05_c0.mif
β”œβ”€β”€ linear_transform_average.txt
β”œβ”€β”€ linear_transform_average_inv.txt
β”œβ”€β”€ linear_transforms
β”œβ”€β”€ linear_transforms_00
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_01
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_02
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_03
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_04
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_05
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_06
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ linear_transforms_07
β”œβ”€β”€ linear_transforms_08
β”œβ”€β”€ linear_transforms_09
β”œβ”€β”€ linear_transforms_10
β”œβ”€β”€ linear_transforms_11
β”œβ”€β”€ linear_transforms_initial
β”‚   β”œβ”€β”€ 0.txt
β”‚   β”œβ”€β”€ 1.txt
β”‚   └── 2.txt
β”œβ”€β”€ log.txt
β”œβ”€β”€ mask_transformed
β”‚   β”œβ”€β”€ 0.mif
β”‚   β”œβ”€β”€ 1.mif
β”‚   └── 2.mif
β”œβ”€β”€ warps_00
β”œβ”€β”€ warps_01
β”œβ”€β”€ warps_02
β”œβ”€β”€ warps_03
β”œβ”€β”€ warps_04
β”œβ”€β”€ warps_05
β”œβ”€β”€ warps_06
β”œβ”€β”€ warps_07
β”œβ”€β”€ warps_08
β”œβ”€β”€ warps_09
β”œβ”€β”€ warps_10
β”œβ”€β”€ warps_11
β”œβ”€β”€ warps_12
β”œβ”€β”€ warps_13
β”œβ”€β”€ warps_14
└── warps_15

You probably best start comparing the current template and previous registration result, which is used for initialisation to the registration that went wrong.

mrcat linear_template05_c0.mif $(mrgrid input_transformed_c0/01170.mif regrid -template linear_template05_c0.mif -) -axis 4 - | mrview - -roi.load mask_transformed/01170.mif -roi.opacity 0.3

shift + right,left in mrview allows you to switch between template (volume group 0) and transformed subject image (1). Look for gross misalignment and global and local large intensity differences between the images as well as poor mask coverage. Affine registration going wrong can usually be traced back to one of these reasons. If your input is not scalar (ODFs), check also a few volumes (right,left in mrview).

If the subject data is grossly misaligned (large rotation or translation) with the template, have a look at the data from previous registration stages:

mrcat linear_template05_c0.mif $(mrtransform  -reorient_fod <yes,no> <INPUT DATA/>01170.mif -template linear_template05_c0.mif -linear linear_transforms_<previous stage number>/01170.txt -) -axis 4 - | mrview -

If your data and mask are OK, you have a few options:

  • don’t include that subject in the template, once the template is done you can register each subject of interest to the template
  • if you have abnormal data (lesions, tumour, artefacts) masked out, use -nanmask to exlude these areas from appearing in the template
  • dilate or erode that subject’s mask to nudge registration in a hopefully better direction
  • experiment with parameters to population_template. For instance, increase the initial scale and number of steps in -affine_scale, set -affine_lmax to zero, or force nonlinear registration to take over the affine part -type rigid_nonlinear (might yield suboptimal results)
  • intervene manually in the registration for that subject using the pause functionality (requires you to experiment with mrregister parameters to overwrite the transformation that went wrong and then press enter once you found settings that worked to continue population_template)
1 Like

Thank you so much for the reply. I really do appreciate it. Quick question. My scratch directory does not contain any of files or folders with _c0. Is this an issue?

Thank You,

Ryan

_c<integer> extensions were introduced with multi-contrast registration, your version of MRtrix3 seems to be not up to date. This might not be a problem, but in general, I’d advise updating to the latest stable version unless you are currently processing a cohort of subjects for which you’d want to freeze the version of the software.