Making a stats mask for 2level dbm output - CoBrALab/documentation GitHub Wiki
This page covers the basics of creating a stats mask for the DBM outputs after running a one- or two-level DBM (see https://github.com/CoBrALab/optimized_antsMultivariateTemplateConstruction).
Here we will walk through the process of registering a mask to the template produced by your DBM. As an example, I will be using mouse brains, but the procedure is the same for humans.
What you need:
- a mask associated with the starting average, final-target/final_target_mask.nii.gz, henceforth referred to as
<mask>
. - the template produced from your dbm run, which can be found within your run directory at
./output/secondlevel/final/average/template_sharpen_shapeupdate.nii.gz
(for a twolevel) henceforth referred to as<template>
- the transforms from the mask (on the original model) to your average: final-target/to_target_0GenericAffine.mat
- the inverse warp file produced by the DBM: final-target/to_target_1InverseWarp.nii.gz
You will essentially just apply the transforms from the DBM to the mask to get it on your template_sharpen_shapeupdate average:
module load minc-toolkit-v2 minc-toolkit-extras ANTs
mask=./final-target/final_target_mask.nii.gz
model=./final-target/final_target.nii.gz
template=../dbm_outputs/template_sharpen_shapeupdate.nii.gz
antsApplyTransforms -d 3 -i $mask -t [ ./final-target/to_target_0GenericAffine.mat,1 ] \
-t ./final-target/to_target_1InverseWarp.nii.gz -o menses_mask.nii.gz -r $template --verbose -n GenericLabel
-d
signifies the images are 3 dimensional
-i
is the input mask
-o
is the name of the output file, which will be the mask on the template.
-t
are your transform files
-r
is your reference image.
-n
the interpolator used will be Generic Label, which is the best interpolator for discrete data (added by the venerable Gabriel A. Devenyi)
--verbose
provides terminal outputs
What you need:
a model average, such as the DSURQE_40micron_average, henceforth referred to as <model> (you may use a higher resolution, resample average here if you created one for your ANTs DBM run)
a mask associated with the model, such as the DSURQE_40micron_mask, henceforth referred to as <mask>
the template produced from your dbm run, which can be found within your run directory at ./output/secondlevel/secondlevel_template0.nii.gz henceforth referred to as <template>
You can use niftis or mncs.
$ module load minc-toolkit-v2 minc-toolkit-extras ANTs
Step 1: Register your template to your model. Here is the command:
$ antsRegistration_affine_SyN.sh --fixed-mask <mask> <template> <model> template_to_model
If you use Step 2: Apply the transformations garnered from Step 1 to the mask so it is fits the template Command:
$ antsApplyTransforms -d 3 -i <mask> -t [ template_to_model0GenericAffine.mat,1 ] \
-t template_to_model1InverseWarp.nii.gz -o mask.nii.gz -r <template> --verbose -n GenericLabel
-d
signifies the images are 3 dimensional
-i
is the input mask
-o
is the name of the output file, which will be the mask on the template.
-t
are your transform files
-r
is your reference image.
-n
the interpolator used will be Generic Label, which is the best interpolator for discrete data (added by the venerable Gabriel A. Devenyi)
--verbose
provides terminal outputs
If you prefer to run use minc files you can do so. Step 1 will be the same, and Step 2 will be the following:
antsApplyTransforms -d 3 -i <mask> -t [ template_to_model0_GenericAffine.xfm,1 ] \
-t template_to_model1_inverse_NL.xfm -o mask.nii.gz -r <template> --verbose -n GenericLabel
Convert your niftis to mncs for analysis in R.
View your mask on your template average.
Display -gray <template.mnc> -grey -label mask.mnc
If your mask seems to fall over the edge a bit, like the example, you may need to erode it.
In the terminal, type:
mincmorph -erosion mask.mnc eroded_mask.mnc
This will perform a single erosion on the mask and output the file eroded_mask.mnc.
You can then display this the same way and visually compare the results!