From a9dc2b4c633f8c432fd7bf66db9b562e6a113eb6 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Thu, 13 Jul 2023 10:42:49 +0100 Subject: [PATCH] TEST: Test for typical/standard MMORF run; needs external/shared data --- mmorf/feedsInputs | 1 + mmorf/feedsRun | 93 +++++++++++++++++++++++++++++++++++++++++ mmorf/mov_to_ref_mm.ini | 60 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100755 mmorf/feedsInputs create mode 100755 mmorf/feedsRun create mode 100644 mmorf/mov_to_ref_mm.ini diff --git a/mmorf/feedsInputs b/mmorf/feedsInputs new file mode 100755 index 0000000..1bf9533 --- /dev/null +++ b/mmorf/feedsInputs @@ -0,0 +1 @@ +mmorf/ diff --git a/mmorf/feedsRun b/mmorf/feedsRun new file mode 100755 index 0000000..89dbb0f --- /dev/null +++ b/mmorf/feedsRun @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +set -e + +thisdir=$(cd $(dirname $0) && pwd) +outdir=$1 +indir=$2/mmorf +benchmarkdir=$3 + +mkdir -p ${outdir}/out + +MMORF_CONFIG=${outdir}/mmorf_config.ini + +cat mov_to_ref_mm.ini | \ + sed "s%##MMORF_INPUT_DIR##%${indir}%g" | \ + sed "s%##MMORF_OUTPUT_DIR##%${outdir}%g" > \ + ${MMORF_CONFIG} + +echo "----------" +echo "MMORF Test" +echo "----------" +echo "" + +# Run MMORF +echo "" +echo "-------------" +echo "Running mmorf" +echo "-------------" +echo "" +mmorf --version --config ${MMORF_CONFIG} + +# Combine warps +echo "" +echo "-------------------" +echo "Running convertwarp" +echo "-------------------" +echo "" +convertwarp -m ${indir}/mov/mov_to_ref.mat -w ${outdir}/out/mov_to_ref_warp -r ${indir}/ref/t1 -o ${outdir}/out/mov_to_ref_warp_combined --rel --relout + +# Resample T1 +echo "" +echo "-----------------" +echo "Running applywarp" +echo "-----------------" +echo "" +applywarp -i ${indir}/mov/t1 -r ${indir}/ref/t1 -w ${outdir}/out/mov_to_ref_warp_combined -o ${outdir}/out/mov_to_ref_t1_nln + +# Resample DTI +echo "" +echo "--------------" +echo "Running vecreg" +echo "--------------" +echo "" +vecreg -i ${indir}/mov/dti -o ${outdir}/out/mov_to_ref_dti_nln -r ${indir}/ref/t1 -w ${outdir}/out/mov_to_ref_warp_combined -m ${indir}/mov/mask_dti --refmask=${indir}/ref/mask_dti + +# Calculate squared differences to expected outputs +echo "" +echo "----------------" +echo "Running fslmaths" +echo "----------------" +echo "" +fslmaths ${outdir}/out/mov_to_ref_warp -inm 1000 ${outdir}/out/mov_to_ref_warp +fslmaths ${outdir}/out/mov_to_ref_warp_combined -inm 1000 ${outdir}/out/mov_to_ref_warp_combined +fslmaths ${outdir}/out/mov_to_ref_jac -inm 1000 ${outdir}/out/mov_to_ref_jac +fslmaths ${outdir}/out/mov_to_ref_bias_1 -inm 1000 ${outdir}/out/mov_to_ref_bias_1 +fslmaths ${outdir}/out/mov_to_ref_t1_nln -inm 1000 ${outdir}/out/mov_to_ref_t1_nln +fslmaths ${outdir}/out/mov_to_ref_dti_nln -inm 1000 ${outdir}/out/mov_to_ref_dti_nln + +fslmaths ${outdir}/out/mov_to_ref_warp -sub ${benchmarkdir}/out/mov_to_ref_warp -sqr -Tmean ${outdir}/out/mov_to_ref_warp_sd +fslmaths ${outdir}/out/mov_to_ref_warp_combined -sub ${benchmarkdir}/out/mov_to_ref_warp_combined -sqr -Tmean ${outdir}/out/mov_to_ref_warp_combined_sd +fslmaths ${outdir}/out/mov_to_ref_jac -sub ${benchmarkdir}/out/mov_to_ref_jac -sqr ${outdir}/out/mov_to_ref_jac_sd +fslmaths ${outdir}/out/mov_to_ref_bias_1 -sub ${benchmarkdir}/out/mov_to_ref_bias_1 -sqr ${outdir}/out/mov_to_ref_bias_1_sd +fslmaths ${outdir}/out/mov_to_ref_t1_nln -sub ${benchmarkdir}/out/mov_to_ref_t1_nln -sqr ${outdir}/out/mov_to_ref_t1_nln_sd +fslmaths ${outdir}/out/mov_to_ref_dti_nln -sub ${benchmarkdir}/out/mov_to_ref_dti_nln -sqr -Tmean ${outdir}/out/mov_to_ref_dti_nln_sd + +# Calculate MSE for each output to expected output +echo "" +echo "----------------" +echo "Running fslstats" +echo "----------------" +echo "" +echo "Warp Field MSE = $(fslstats ${outdir}/out/mov_to_ref_warp_sd -k ${indir}/ref/mask_dti -m)" +echo "Jac Det MSE = $(fslstats ${outdir}/out/mov_to_ref_jac_sd -k ${indir}/ref/mask_dti -m)" +echo "Bias Field MSE = $(fslstats ${outdir}/out/mov_to_ref_bias_1_sd -k ${indir}/ref/mask_dti -m)" +echo "Combined Warp MSE = $(fslstats ${outdir}/out/mov_to_ref_warp_combined_sd -k ${indir}/ref/mask_dti -m)" +echo "T1 Nonlin MSE = $(fslstats ${outdir}/out/mov_to_ref_t1_nln_sd -k ${indir}/ref/mask_dti -m)" +echo "DTI Nonlin MSE = $(fslstats ${outdir}/out/mov_to_ref_dti_nln_sd -k ${indir}/ref/mask_dti -m)" + +echo "" +echo "-------------" +echo "TEST COMPLETE" +echo "-------------" +echo "" diff --git a/mmorf/mov_to_ref_mm.ini b/mmorf/mov_to_ref_mm.ini new file mode 100644 index 0000000..2bd0869 --- /dev/null +++ b/mmorf/mov_to_ref_mm.ini @@ -0,0 +1,60 @@ +; Values only set once +warp_res_init = 32 +warp_scaling = 1 1 2 2 +img_warp_space = ##MMORF_INPUT_DIR##/ref/t1 +lambda_reg = 4.0e5 3.7e-1 3.1e-1 2.6e-1 +hires = 12 +optimiser_max_it_lowres = 5 +optimiser_max_it_hires = 5 + +; T1 with no masking and no bias field +img_ref_scalar = ##MMORF_INPUT_DIR##/ref/t1 +img_mov_scalar = ##MMORF_INPUT_DIR##/mov/t1 +aff_ref_scalar = ##MMORF_INPUT_DIR##/ref/identity.mat +aff_mov_scalar = ##MMORF_INPUT_DIR##/mov/mov_to_ref.mat +use_implicit_mask = 0 +use_mask_ref_scalar = 0 0 0 0 +use_mask_mov_scalar = 0 0 0 0 +mask_ref_scalar = NULL +mask_mov_scalar = NULL +fwhm_ref_scalar = 8.0 8.0 4.0 2.0 +fwhm_mov_scalar = 8.0 8.0 4.0 2.0 +lambda_scalar = 0.1 0.1 0.1 0.1 +estimate_bias = 0 +bias_res_init = 16 +lambda_bias_reg = 1e9 1e9 1e9 1e9 + +; T1 with masking and bias field +img_ref_scalar = ##MMORF_INPUT_DIR##/ref/t1 +img_mov_scalar = ##MMORF_INPUT_DIR##/mov/t1 +aff_ref_scalar = ##MMORF_INPUT_DIR##/ref/identity.mat +aff_mov_scalar = ##MMORF_INPUT_DIR##/mov/mov_to_ref.mat +use_implicit_mask = 0 +use_mask_ref_scalar = 1 1 1 1 +use_mask_mov_scalar = 1 1 1 1 +mask_ref_scalar = ##MMORF_INPUT_DIR##/ref/mask_t1 +mask_mov_scalar = ##MMORF_INPUT_DIR##/mov/mask_t1 +fwhm_ref_scalar = 8.0 8.0 4.0 2.0 +fwhm_mov_scalar = 8.0 8.0 4.0 2.0 +lambda_scalar = 1 1 1 1 +estimate_bias = 1 +bias_res_init = 16 +lambda_bias_reg = 1e9 1e9 1e9 1e9 + +; First tensor pair +img_ref_tensor = ##MMORF_INPUT_DIR##/ref/dti +img_mov_tensor = ##MMORF_INPUT_DIR##/mov/dti +aff_ref_tensor = ##MMORF_INPUT_DIR##/ref/identity.mat +aff_mov_tensor = ##MMORF_INPUT_DIR##/mov/mov_to_ref.mat +use_mask_ref_tensor = 1 1 1 1 +use_mask_mov_tensor = 1 1 1 1 +mask_ref_tensor = ##MMORF_INPUT_DIR##/ref/mask_dti +mask_mov_tensor = ##MMORF_INPUT_DIR##/mov/mask_dti +fwhm_ref_tensor = 8.0 8.0 4.0 2.0 +fwhm_mov_tensor = 8.0 8.0 4.0 2.0 +lambda_tensor = 1 1 1 1 + +; Output warp +warp_out = ##MMORF_OUTPUT_DIR##/out/mov_to_ref_warp +jac_det_out = ##MMORF_OUTPUT_DIR##/out/mov_to_ref_jac +bias_out = ##MMORF_OUTPUT_DIR##/out/mov_to_ref_bias \ No newline at end of file -- GitLab