When creating a mask using 3dmask_tool, the mask experienced abnormal dilation

Hi all,
I ran the 3dmask_tool to create anatomy mask. Before that, I first ran the 3dresample program to resample a mask on the MNI standard template to match the functional image resolution. But when i tried to convert it to binary anat mask and fill gaps and holes, the mask dilated to a abnormal scale(see Figure). And when I examined GLM results, many data points clearly deviated from the MNI spatial template due to this bug mask (what I think).

I don’t understand why the final mask is significantly larger than the actual requirement; any advice would be greatly appreciated.

My code is as follows: I tried adjusting the dilate level , for example, 2-2 , or not using the dilate option, but the generated mask ends up resembling Figure .

! 3dresample -master full_mask.{subj}.nii.gz -input \
           MNI152_2009_template_SSW.nii.gz -prefix rm.resam.anat.nii.gz
# convert to binary anat mask; fill gaps and holes
! 3dmask_tool -dilate_input 5 -5 -fill_holes -input rm.resam.anat.nii.gz \
            -prefix mask_anat.{subj}.nii.gz

Hi-

Interesting. The issue here appears to be that MNI152_2009_template_SSW.nii.gz is a multibrick volume, as described here. In the first 3dresample command, therefore, rm.resam.anat.nii.gz is also a multibrick volume. When you put that into 3dmask_tool, it isn't the [0]th volume that is being inflated/dilated but actually a different one---I believe the [1]st volume, which is a full-head dataset (not just a brain). So you are actually inflating/deflating that one, which is why it appears so big.

Can you try running this instead---note the subbrick selector in the first command

3dresample                                                      \
    -master  full_mask.{subj}.nii.gz                            \
    -input   MNI152_2009_template_SSW.nii.gz'[0]'               \
    -prefix  rm.resam.anat.nii.gz
# convert to binary anat mask; fill gaps and holes
3dmask_tool                                                     \
    -dilate_inputs  5 -5                                        \
    -fill_holes                                                 \
    -input          rm.resam.anat.nii.gz                        \
    -prefix         mask_anat.{subj}.nii.gz

--pt

To be a little more specific, 3dmask_tool takes multi-volume inputs, and they are treated as a list of inputs, and the default multi-volume processing is to compute a union mask. So this will (intentionally) compute a union mask across the volumes.
While one might not expect the template dataset to have multiple volumes, the 3dmask_tool output does at least mention it (somewhat subtly):

++ no -frac option: defaulting to -union
++ processing 1 input dataset(s), NN=2...
++ padding all datasets by 5 (for dilations)
++ frac 0 over 5 volumes gives min count 0
...
  • rick

Fascinating! I learned something new today.

Thanks for clarifying that.

--pt

The number of volumes will be separated out to make it slightly more clear (though still at that point in the program and therefore a few lines into the output text):

++ have 5 volumes of input
  • rick

By running your code, I did solve the problem. I think I'll be more careful with the AFNI output prompts after that, thank you very much!

Your explanation made me suddenly realize, thank you for providing a more detailed clarification!

Indeed, Rick's comment and solution here is the more important one. I hadn't understood how 3dmask_tool would deal with a multi-volume input, but that is the real point of explaining the behavior.

It makes sense that a common use case might be to "stack" masks from multiple subjects into a single, 4D dataset, and then want to operate on them and unionize them. I just hadn't ever stumbled across this functionality, myself.

We have updated some of the terminal+help text to make this clearer. Thanks for raising this question.

--pt

One more point here is that the inputs and outputs are assumed to be masks, so non-zero positive values are typically what you want. Multiple sub-bricks are interpreted as multiple input volumes. If you want a specific volume for the MNI 2009c template we distribute, then use the single volume MNI152_2009_template.nii.gz dataset or specify the zeroth volume of MNI152_2009_template_SSW.nii.gz'[0]'. I tend to use the former to avoid problems like these.