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)

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