#!/bin/bash

cd /mnt/c/Users/gargy/OneDrive/Desktop/7TAMI/cropped/
###List of ROIs
rois=("7TAMI_L_AV.nii" \
"7TAMI_R_AV.nii" \
"7TAMI_L_CL.nii" \
"7TAMI_R_CL.nii" \
"7TAMI_L_CM.nii" \
"7TAMI_R_CM.nii" \
"7TAMI_L_LGN.nii" \
"7TAMI_R_LGN.nii" \
"7TAMI_L_MGN.nii" \
"7TAMI_R_MGN.nii" \
"7TAMI_L_Pu.nii" \
"7TAMI_R_Pu.nii" \
"7TAMI_L_MD.nii" \
"7TAMI_R_MD.nii")

	# Define input files
	input_t1="/mnt/c/Users/gargy/OneDrive/Desktop/7TAMI/unzipped/7TAMI_T1w_30.nii"
	target_t1="/mnt/c/Users/gargy/OneDrive/Desktop/7TAMI/cropped/c7TAMI_T1w_30_cropped.nii"

	# Output base name for transformation matrix
	xfm="T1_to_cropped_affine.mat"

	# Coregister T1_brain to the cropped/reoriented version (linear)
	flirt -in "$input_t1" -ref "$target_t1" -out "T1_brain_coregistered.nii" -omat "$xfm" -dof 6

	# Loop through all binary ROI masks (must be in same space as T1_brain)
	for roi in "${rois[@]}"; do
		base=$(basename "$roi" .nii)
			flirt -in "$roi" \
			-ref "$target_t1" \
			-applyxfm -init "$xfm" \
			-interp nearestneighbour \
			-out "${base}_coreg.nii"
	done

