#!/bin/bash module load afni #2022 module load ANTs/20150828 #in our system this is ants/2.1.0 module unload fsl #need to unload crashy version of fsl module load fsl/6.0.5 #not crashy version of fsl cd /sub-aRi114/ #two folders, anat, dwi. template="DSURQE_100micron_average.nii.gz" template_mask="DSURQE_100micron_mask_dilated.nii.gz" anat_file=/anat/"sub-aRi114_ses-1_T2w.nii.gz" anat2temp='anat2temp.nii.gz' anat2temp_inv='anat2temp_inv.nii.gz' anat_base=$(basename ${anat_file}) anat_noext="$(remove_ext ${anat_base})" echo Anatomical file: ${anat_file} echo Template mask: ${template_mask} echo Anatomical base: ${anat_base} echo Anatomical noext: ${anat_noext} echo Anatomical anat2temp: ${anat2temp} echo Anatomical inverse_anat2temp: ${anat2temp_inv} mkdir -p tmp_data/anat cp anat/* tmp_data/anat || { echo Failed to copy files; exit 1; } cp * tmp_data/anat cd tmp_data/anat 3drefit -deoblique -overwrite ${anat_base} 3dresample -orient lpi -prefix ${anat_noext}'_lpi.nii.gz' -input ${anat_base} 3dAutobox -prefix ${anat_noext}'_auto.nii.gz' -input ${anat_noext}'_lpi.nii.gz' N4BiasFieldCorrection -d 3 -i ${anat_noext}'_auto.nii.gz' -o ${anat_noext}'_N4.nii.gz' DenoiseImage -d 3 -i ${anat_noext}'_N4.nii.gz' -o ${anat_noext}'_N4_dn.nii.gz' ImageMath 3 ${anat_noext}'_N4_dn.nii.gz' TruncateImageIntensity ${anat_noext}'_N4_dn.nii.gz' 0.05 0.999 fslmaths 'sub-aRi114_ses-1_T2w_mask.nii.gz' -kernel 3D -dilM ${anat_noext}'_mask_dilated.nii.gz' anat_mask=${anat_noext}'_mask_dilated.nii.gz' echo Anatomical mask: ${anat_mask} mkdir -p reg antsRegistration --dimensionality 3 --float 0 -a 0 -v 1 --output reg/anat2std --interpolation Linear --winsorize-image-intensities [0.005,0.995] --use-histogram-matching 0 --initial-moving-transform [DSURQE_100micron_average.nii.gz,${anat_noext}'_N4_dn.nii.gz',1] --transform Rigid[0.1] --metric MI[DSURQE_100micron_average.nii.gz,${anat_noext}'_N4_dn.nii.gz',1,32,Regular,0.25] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[0.1] --metric MI[DSURQE_100micron_average.nii.gz,${anat_noext}'_N4_dn.nii.gz',1,32,Regular,0.25] --convergence [1000x500x250x100,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[0.1,3,0] --metric CC[DSURQE_100micron_average.nii.gz,${anat_noext}'_N4_dn.nii.gz',1,4] --convergence [30x20x10x5,1e-6,10] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --masks [${template_mask},${anat_mask}] ComposeMultiTransform 3 ${anat2temp} -R DSURQE_100micron_average.nii.gz reg/anat2std1Warp.nii.gz reg/anat2std0GenericAffine.mat ComposeMultiTransform 3 ${anat2temp_inv} -R DSURQE_100micron_average.nii.gz -i reg/anat2std0GenericAffine.mat reg/anat2std1InverseWarp.nii.gz antsApplyTransforms -i ${anat_noext}'_N4_dn.nii.gz' -r DSURQE_100micron_average.nii.gz -t ${anat2temp} -o ${anat_noext}'_2std.nii.gz' slicer ${anat_noext}'_2std.nii.gz' DSURQE_100micron_average.nii.gz -s 2 -x 0.35 sla.png -x 0.45 slb.png -x 0.55 slc.png -x 0.65 sld.png -y 0.35 sle.png -y 0.45 slf.png -y 0.55 slg.png -y 0.65 slh.png -z 0.35 sli.png -z 0.45 slj.png -z 0.55 slk.png -z 0.65 sll.png ; pngappend sla.png + slb.png + slc.png + sld.png + sle.png + slf.png + slg.png + slh.png + sli.png + slj.png + slk.png + sll.png highres2standard1.png ; slicer DSURQE_100micron_average.nii.gz ${anat_noext}'_2std.nii.gz' -s 2 -x 0.35 sla.png -x 0.45 slb.png -x 0.55 slc.png -x 0.65 sld.png -y 0.35 sle.png -y 0.45 slf.png -y 0.55 slg.png -y 0.65 slh.png -z 0.35 sli.png -z 0.45 slj.png -z 0.55 slk.png -z 0.65 sll.png ; pngappend sla.png + slb.png + slc.png + sld.png + sle.png + slf.png + slg.png + slh.png + sli.png + slj.png + slk.png + sll.png highres2standard2.png ; pngappend highres2standard1.png - highres2standard2.png anat2template.png; rm -f sl?.png highres2standard2.png rm highres2standard1.png