Applying exclusion masks

Good afternoon,

I am trying to apply inclusion masks as well as exclusion masks for tractography. I have defined the masks using 3dUndump, giving coordinates and radius of my inclusion/exclusion sphere as follows:

3dUndump \
 -master $BASE/$SUBJ/INTERMED/DTI/dt_FA.nii.gz \
 -xyz \
 -srad 4 \
 -prefix $BASE/$SUBJ/INTERMED/IFOF_LHS_EXCL \
 IFOF_LHS_EXCL.txt

And then use the following code to warp this ROI/mask from my reference subject to all the other subjects:

   # Compute nonlinear warp: subj -> reference (FA volume as base)
3dQwarp \
     -base $BASE_REF/INTERMED/DTI/dt_FA.nii.gz \
     -allineate   \
     -source $BASE/$SUBJ/INTERMED/DTI/dt_FA.nii.gz \
     -maxlev 4    \
     -prefix $BASE/$SUBJ/INTERMED/subj2ref \
     -overwrite

# Apply warp to IFOF_INCL mask (nearest neighbor to stay binary)
    3dNwarpApply \
        -source $THRU_MASK_REF \
        -nwarp "INV($BASE/$SUBJ/INTERMED/subj2ref_WARP+orig)" \
        -master $BASE/$SUBJ/INTERMED/DTI/dt_FA.nii.gz \
        -interp NN \
        -prefix $BASE/$SUBJ/INTERMED/IFOF_LHS_INCL \
        -overwrite

# Apply warp to IFOF_EXCL mask (nearest neighbor to stay binary)
    3dNwarpApply \
        -source $EXCL_MASK_REF \
        -nwarp "INV($BASE/$SUBJ/INTERMED/subj2ref_WARP+orig)" \
        -master $BASE/$SUBJ/INTERMED/DTI/dt_FA.nii.gz \
        -interp NN \
        -prefix $BASE/$SUBJ/INTERMED/IFOF_LHS_EXCL \
        -overwrite

3dcalc \
   -a $BASE/$SUBJ/INTERMED/IFOF_LHS_INCL+orig \
   -b $BASE/$SUBJ/INTERMED/IFOF_LHS_EXCL+orig \
   -expr 'step(a)*iszero(step(b))' \
   -prefix $BASE/$SUBJ/INTERMED/IFOF_LHS_ALLOWED \
   -overwrite

I am unsure of whether the -expr 'step(a)*iszero(step(b))' expression is correct for "including" the inclusion mask but "excluding" the exclusion mask.

Any help would be greatly appreciated.

That 3dcalc expression means use the inclusion mask and not the exclusion mask. If a voxel is marked as both inclusion and exclusion, it won't be in the result, so I think that's what you want.

Moving a sphere from one space to another with a nonlinear warp will result in something not spherical in the target space. You may want to transform the center coordinate of the sphere instead with 3dNwarpXYZ instead, and then make a sphere around that. Note the transformation is the opposite direction for that command relative to 3dNwarpApply, so you may want to invert that on the command line or reverse and invert the transformation string. In this case, with the allineate done by 3dQwarp, the inverting of the INV(...) would mean just removing the INV from the string.

Howdy-

Just to note, when tracking with 3dTrackID you have:

  • "target" ROIs in the network (find connections running into/between regions)
  • "exclusion" ROIs: forbid tracts from passing through (like Gandalf to the Balrog's path in the Mines of Moria, surely a helpful reference)
  • "thru" ROIs: require tracts to run through this region, as an extra condition, for any network connections.

Additionally, the user can provide a wholebrain mask, through which tracts are constrained to run.

The "target" and "exclusion" ROIs are each defined in the dataset provided via -netrois ... Regions with positive integer values are "target" ROIs, and regions with negative ROIs are "exclusion" ROIs. So, only these two types of ROIs are provided in a single volume, which you could do with 3dcalc (see below).

The "thru" (or, "through") ROIs are provided with the -thru_mask .. option. And the mask is provided with -mask ...

So, if you have a two dsets that are maps of ROIs, and you want the one provided with -a .. to be target ROIs and -b .. to be exclusion ROIs, and each are initially made up of integer values then you could do:

# if you are SURE the two dsets' ROIs do not overlap
3dcalc -a DSET_TARG -b DSET_EXCL -expr "a-b" -prefix DSET_TARG_AND_EXCL

# if there might be overlap, and you want to prioritize a
3dcalc -a DSET_TARG -b DSET_EXCL -expr "a-not(a)*b" -prefix DSET_TARG_AND_EXCL

... and you could move "not(...)" to prioritize "B" above, if you wanted.

Does that make sense? Please let me know if I have made any mistake about the desired dset/data types.

--pt