3dQwarp and automask usage

This question has been split into a separate thread from where it was originally asked (which was here: https://afni.nimh.nih.gov/afni/community/board/read.php?1,162857,162877#msg-162877).

It is a separate question, so it should have its own thread. In the future, please address new questions with separate threads, for readability.


Hi AFNI Experts,
I wanted to get some clarification on 3dQwarp and automask as well as the interaction -weight as I may have an issue as well. In the 3dQwarp -emask documentation it states the following:

The base image always automasked – the emask is
extra, to indicate voxels you definitely DON’T want
included in the matching process, even if they are
inside the brain.

This suggests that the base image is always auto masked regardless of weight options as a first step. Since there is no way to pass a clip fraction I assume 3dAutomask with a default clip fraction of 0.4 is used. On my T2 image this seems to exclude most of the brainstem on a particular subject.

  1. If I pass a custom weight image that includes the brainstem, would this brainstem area be used or skipped since the automask does not include the brainstem in this case? In other words, does the -weight option take precedence over the automatic use of automasking in 3dQwarp? Is the automasking only used as part of creating a weight in 3dQwarp or is the image itself actually masked prior to matching?

  2. If the 3dAutomask is always used first, is it possible to expose a clip fraction parameter for us to adjust, as well as include a way to save the mask out for troubleshooting?


The logic of 3dAutomask with a clip level of 0.33 is used to form the base image automask, after the base image is smoothed a little (4.5 voxels FWHM). Then the voxels surviving inside the automask are scaled to make the weight. This is the only function of the automask. The alignment proceeds with the weight volume which is separate from the base image volume. That volume is usually blurred a little but not otherwise processed for the matching algorithm. However, the parts of it that were outside the automask will not count at all in the matching algorithm, and will “flap in wind” of the nonlinear deformations from the other voxels. You can see what the automatically computed weight volume is by using the “-wtprefix” option to 3dQwarp.

If you supply your own weight volume, the whole blur+automask procedure is skipped in favor of your own weight volume. Note that the “-wball” option does not apply to a user-supplied weight volume. “-emask” does apply in either case (automatic or user-supplied weight).

There is no option to set the clip level (or other parameters) of the automatic weight volume computation. There are several such parameters, and it seems overly complicated to let these be adjusted – you are the first person ever to ask about anything like that.

I hope this helps explain the process. If you are aligning T2-weighted images, then perhaps a little more care is needed, since the program has been tested mostly on T1-weighted images. What are you aligning TO - a template?

Hi Bob,
Thanks for the explanation on how the weighting etc works within the program. I was using my own weight to emphasize areas where alignment is most crucial when warping. When reading through the emask option and testing with the default .4 clip fraction from 3dAutomask I worried that one of the areas in the brainstem would be excluded that I am emphasizing, which is where my questions came from. When testing with the clip fraction of .33 (not realizing this is the default in 3dQwarp as opposed to 3dAutomask’s default) the brainstem was covered and I reconfirmed this with the wtprefix option you suggested so it seems all this won’t be an issue. At this time, I am aligning to a T2 weighted template space for some subcortical regions that are more easily distinguishable on this contrast as opposed to the T1 template.


You might experiment with pre-processing your subjects’ T2 datasets with 3dUnifize and its ‘-T2’ option.

Also, you can (with the default weighting) use the ‘-wball’ option to add more weight to the region you like the most. My limited experiments on this, focusing on the thalamus, used ‘-wball 0 14 6 30 40’ where ‘0 14 6’ are the xyz coordinates of the ball’s center, 30 is its radius, and 40 is the intensification factor for the weight. That factor of 40 might sound large, but since the ball is small in volume relative to the brain, the extra weight doesn’t have much effect unless the weight is increased a lot there.

Paul has been urging me to upgrade 3dQwarp to allow alignment using multiple types of images at once – T1 and T2, for example, or (in his case), diffusion tensor images. Maybe someday. I know HOW to do it in the code, but there are a lot of details that have to been addressed to make it work correctly. Also, such an alignment will take a significant amount of memory!

Hi Bob,
Thanks again for the suggestions. I agree it is great to incorporate but there are definitely several technical challenges such as dealing with differing distortions between modalities (i.e. diffusion vs fMRI vs structural) that will make it a bit more challenging , along with system requirements. Maybe limiting it to structural scans with little distortions such as T1/T2/proton density would be a good first step as it may limit the memory usage and be less susceptible to distortions within subject leading to more robust results. I will definitely keep my eye out and test if you decide to go down this route in the future.