Ordering of Options in Commands

Alert reader Surya recently pointed out how using different masks in the command fslstats led to the same result, leading her to question whether there was an error when creating the masks. 

The actual cause of the error, however, was in how the command was constructed. Here was the initial syntax:

fslstats image.nii.gz -M -k mask.nii.gz

Which reads the -M flag as meaning to calculate the mean, and the -k flag as meaning to use the specified mask. This command contains everything needed to do an ROI analysis, but the order of the options is wrong.

Imagine that the command is a real person, and that he reads from left to right, just like we do. The above command reads in the image and is ready to apply the option that comes next. What comes next is the -M flag, which instructs the command to take the mean, which is interpreted as: Take the mean of the entire image. The command then runs into the -k flag, which means to apply a mask. Yet there is nothing at this stage for the mask to do; the mean has already been calculated.

To make the command do what we want, a rearrangement of the flags is necessary:

fslstats image.nii.gz -k mask.nii.gz -M

This is it. The command reads in the image, then applies the mask, and then returns the value of the mean of the voxels inside that mask. A small difference in the code, but an important change in the result.

Keep in mind that most commands are like this. When in doubt, read the command left to right and imagine the events unfolding linearly in time; this can help both with debugging, and with training your imagination to more perfectly align with how to write these commands.