Creating FOD population template using nan-masking

Dear all,

I have a question concerning the ‘population_template’ command. I am trying to create a fod population template whilst mitigate the effects of brain cropping on my data following the instructions [here](https://mrtrix.readthedocs.io/en/latest/fixel_based_analysis/mitigating_brain_cropping.html#mitigating-brain-cropping).
For that, I want to NaN-mask my images to avoid using areas outside of the FOV in the aggregate metric when creating the population template. I did the following:

  1. Create nanned brain masks for each participant via the following command:
for_each * : mrtreshold IN/dwi_mask.mif IN/dwi_mask_nanned.mif -abs 0.0 -comparison gt -nan
  1. Nanned the wmfod images for each participant via the following command:
for_each * : mrcalc IN/wmfod_norm.mif IN/dwi_mask_nanned.mif -mult IN/wmfod_norm_nanned.mif

Now, I want to create the population template by averaging all the values that are not ‘nan’ in the image. For this I thought about several options to run the command population template (see below). I wonder whether these options will give the same results or if one option would be better than the others?

Option

  • Option A: using the nanned wmfod images as input + the nanned masks (values of NaN or 1) + the option “-nanmask”
    population_template fod_input_nanned -mask_dir mask_input_nanned -nanmask -aggregate median wmfod_template_A.mif -voxel_size 1.3
    
  • Option B: using the nanned wmfod images as input WITHOUT a mask dir and WITHOUT the option “-nanmask”
      population_template fod_input_nanned -aggregate median wmfod_template_B.mif -voxel_size 1.3
    
  • Option C: using the normal fod images + the nanned masks (values of NaN or 1) + the option “-nanmask”
    population_template fod_input_NOTnanned -mask_dir mask_input_nanned -nanmask -aggregate median wmfod_template_C.mif -voxel_size 1.3
    
  • Option D: using the normal fod images + the normal masks (values of 0 or 1) + the option “-nanmask”
    population_template fod_input_NOTnanned -mask_dir mask_input_NOTnanned -nanmask -aggregate median wmfod_template_C.mif -voxel_size 1.3
    

I thus wonder whether all of these options would give the same result or if one option would be better than the others?

Thank you for your advice.
Maud

Welcome Maud!

Unless the very esoteric distinctions between these is of importance to you—in which case I would suggest performing a more comprehensive evaluation and code review—the simplest to my mind is to ensure that the masks do not contain any zero-filled voxels, skip steps 1 and 2, and use the -nanmask option, so option D. That option will trigger internal operations wherein FOD data get NaN-filled based on the content of the respective masks, but it does so internally within its optimisation. Pre-NaN-ing input data would probably make minimal difference; I could hypothesize how it might differ subtlely, but the time required to elucidate it would be better spent toward a more comprehensive revision of these instructions, which has recently involved specifically this point.

I find the idea of introducing NaN values into a mask image counter-intuitive for a couple of reasons:

  1. We typically think of a “mask” as being a bitwise image, whereas NaNs cannot be represented with a bitwise datatype, so persisting with calling it a “mask” is a slight misnomer.
  2. If the information about the spatial extent of a mask is encoded by the presence of NaNs within the corresponding image data, then that mask no longer provides any informative data over and above what’s present in the image data, and therefore providing it as secondary input could only, in the best case scenario, have no net effect.

Regards
Rob

2 Likes