How to merge MNI and PAM50 template?


Now that the PAM50 and MNI templates are in the same physical space, it is possible to merge them in order to obtain a single image encompassing both templates, like this:

I was asked several times how to do it, so I though it would be useful to describe the recipe in this forum:

# Pad the MNI template
sct_image -i /usr/local/fsl/data/standard/MNI152_T1_0.5mm.nii.gz -pad-asym 0,0,100,0,300,0 -o MNI152_T1_0.5mm_pad.nii.gz
# Bring the PAM50_t1 template into the padded MNI space
sct_register_multimodal -i ${SCT_DIR}/data/PAM50/template/PAM50_t1.nii.gz -d MNI152_T1_0.5mm_pad.nii.gz -identity 1
# Scale the intensity of the PAM50 template to match that of the MNI template (signal value estimated at 160 in the white matter of the ICBM152_0.5 template)
sct_maths -i PAM50_t1_reg.nii.gz -div 6.25 -o PAM50_t1_reg_norm.nii.gz
# Mask the PAM50 above a given slice
sct_crop_image -i PAM50_t1_reg_norm.nii.gz -dim 2 -start 0 -end 310 -b 0 -o PAM50_t1_reg_norm_crop.nii.gz
# Mask the MNI template below the same slice
sct_crop_image -i MNI152_T1_0.5mm_pad.nii.gz -dim 2 -start 311 -end 644 -b 0 -o MNI152_T1_0.5mm_pad_crop.nii.gz
# Add the PAM50 to the padded MNI template image
sct_maths -i MNI152_T1_0.5mm_pad_crop.nii.gz -add PAM50_t1_reg_norm_crop.nii.gz -o MNI152-PAM50_T1_0.5mm.nii.gz
# And the magic happens!
fsleyes MNI152-PAM50_T1_0.5mm.nii.gz &

Of course you can also play with other field of view (i.e. extend the PAM50 further down), contrasts (T2, T2s) and resolution (1mm, 2mm) offered by the ICBM152 MNI template.