Repository navigation
Expand file tree
/
Copy pathStructural_Targeting.sh
More file actions
50 lines (35 loc) · 2.7 KB
/
Copy pathStructural_Targeting.sh
File metadata and controls
50 lines (35 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#This script will recieve 4 input arguments and will output transformed ROI masks from MNI space into T1w subject space and save them in an output path. It will read the mask files and then perform the correct linear and non-linear registration from STD space to Subject Space.
##INPUT 1: Full path to raw structural T1w file that has gone through the necessary flywheel gear
#INPUT 2: Full path of the directory containing all masks that needs adjustment (in a 3D NIFTI format) - Preferrably in a 1mm , standard MNI space
#INPUT 3: A Full Path to the Brain Extracted template matching the space and dimentions of the input mask (input 2)
#INPUT 4: A Full path of the directory for output masks (will be saved in a 3D NIFTI format)
# -----------------------------------------------Establishing file tags and setting up output. No registrations decisions made here ----------------------
T1=$1
ROI_DIR=$2
STD=$3
OUT_DIR=$4
mkdir -p $OUT_DIR
SUB=$(basename "${T1}" | cut -d. -f1)
MASK_ADJ_DATA_DIR=MASK_TRANSFORM_DATA
mkdir -p $MASK_ADJ_DATA_DIR
# -----------------------------------------------Cleaning the T1 and brain extracting it. Still not making a decision about which registration tool to use -----------------
#Brain extracting the T1
N4BiasFieldCorrection -d 3 -i ${T1} -o ${T1}
bet ${T1} ${MASK_ADJ_DATA_DIR}/${SUB}_bet.nii.gz -f 0.25 -R -B
# -----------------------------------------------Begin ANTs Registration Comment out if we are bailing on ANTs----------------------------------------------------
#Performing the initial Affine Registration with ANTs
antsRegistrationSyN.sh -d 3 -m ${MASK_ADJ_DATA_DIR}/${SUB}_bet.nii.gz -f $STD -o ${MASK_ADJ_DATA_DIR}/t1_to_MNI_aff_ -t a -r 2 -j 1
#Performing the non-linear registration with ANTs
antsRegistrationSyN.sh -d 3 -m ${MASK_ADJ_DATA_DIR}/t1_to_MNI_aff_Warped.nii.gz -f $STD -o ${MASK_ADJ_DATA_DIR}/t1_to_MNI_opt_ -t b -r 2 -j 1
#Applying the transformation to the masks with ANTs
echo Transforming masks...
for ROI in ${ROI_DIR}/*.nii.gz; do
MASK=$(basename "${ROI}" | cut -f 1 -d '.')
antsApplyTransforms -d 3 -r ${MASK_ADJ_DATA_DIR}/${SUB}_bet.nii.gz -i $ROI -o ${OUT_DIR}/NTV_${MASK}.nii.gz -n NearestNeighbor -t [${MASK_ADJ_DATA_DIR}/t1_to_MNI_aff_0GenericAffine.mat,1] -t [${MASK_ADJ_DATA_DIR}/t1_to_MNI_opt_0GenericAffine.mat,1] -t ${MASK_ADJ_DATA_DIR}/t1_to_MNI_opt_1InverseWarp.nii.gz
#Binarizing the Mask Output
fslmaths ${OUT_DIR}/NTV_${MASK}.nii.gz -bin ${OUT_DIR}/NTV_${MASK}.nii.gz
gunzip ${OUT_DIR}/*nii.gz
# -----------------------------------------------End of ANTs Registration. Do not remove the following command-----------------------------------------------
fslstats -t ${OUT_DIR}/NTV_${MASK}.nii -c > ${OUT_DIR}/NTV_${MASK}_CRD.txt
done