#Apply the registrations to the structural images (note that we do not resample; we just update the header).

#!/bin/bash

# List of folders
folders=("mgh_1001" \
"mgh_1008" \
"mgh_1015" \
"mgh_1022" \
"mgh_1029" \
"mgh_1002" \
"mgh_1009" \
"mgh_1016" \
"mgh_1023" \
"mgh_1030" \
"mgh_1003" \
"mgh_1010" \
"mgh_1017" \
"mgh_1024" \
"mgh_1031" \
"mgh_1004" \
"mgh_1011" \
"mgh_1018" \
"mgh_1025" \
"mgh_1032" \
"mgh_1005" \
"mgh_1012" \
"mgh_1019" \
"mgh_1026" \
"mgh_1033" \
"mgh_1006" \
"mgh_1013" \
"mgh_1027" \
"mgh_1034" \
"mgh_1007" \
"mgh_1014" \
"mgh_1021" \
"mgh_1028")

# get the lta (perform within-subject, cross-modal registration using a boundary-based cost function)
 for folder in "${folders[@]}"; do
 SUBJECTS_DIR=/mnt/e/HCP35/unzipped/${folder}/anat/T1;
 bbregister \
 --s T1 \
 --mov /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/dtifit_FA.nii.gz \
 --reg /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/xfms/anatorig2diff.bbr.lta \
 --init-fsl \
 --dti
 done

# apply the lta
for folder in "${folders[@]}"; do
SUBJECTS_DIR=/mnt/e/HCP35/unzipped/${folder};

mri_vol2vol --nearest --mov /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/mri/norm.mgz \
--o /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/mri/norm.dwispace.mgz --no-resample \
--lta /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/xfms/anatorig2diff.bbr.lta \
--targ /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/dtifit_FA.nii.gz \
--interp cubic;

mri_vol2vol --nearest --mov /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/mri/aseg.mgz \
--o /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/mri/aseg.dwispace.mgz --no-resample \
--lta /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/xfms/anatorig2diff.bbr.lta \
--targ /mnt/e/HCP35/unzipped/${folder}/anat/T1/T1/dmri/dtifit_FA.nii.gz \
--interp cubic;
done
