johneusebio
1/6/2017 - 10:21 PM

This script creates spherical ROIs around specified points using FSL.

This script creates spherical ROIs around specified points using FSL.

TOP_DIR='/mnt/c/Users/john/OneDrive/2016-2017/mri_files'
OUT_DIR='/mnt/c/Users/john/OneDrive/2016-2017/mri_files'
TEMPLATE='MNI152_T1_2mm_brain.nii.gz'
ROI_PTS=$TOP_DIR/'roi_pts.txt'
RAD=5

REMOVE_INTERMEDIATES=true

cd $TOP_DIR

COUNT=0
while read -r point; do
	COUNT=$(expr $COUNT + 1)

	read -r -a coords <<< "$point"
	fslmaths $TEMPLATE -mul 0 -add 1 -roi ${coords[0]} 1 ${coords[1]} 1 ${coords[2]} 1 0 1 $OUT_DIR/pt_$COUNT -odt float
	fslmaths $OUT_DIR/pt_$COUNT -kernel sphere $RAD -fmean $OUT_DIR/sphere_$COUNT -odt float
done < $ROI_PTS

cd $OUT_DIR

ROI_FILES=($(ls sphere_*))

merge_line=''
for ROI in ${ROI_FILES[@]:1:${#ROI_FILES[@]}}; do
	merge_line=$(echo $merge_line -add $ROI)
done

fslmaths ${ROI_FILES[0]} $merge_line merged_rois

if [ "$REMOVE_INTERMEDIATES" = true ]; then
	rm pt_*.nii.gz
	rm sphere_*.nii.gz
fi