diff --git a/dice_score_local.sh b/dice_score_local.sh new file mode 100644 index 0000000..0c6be09 --- /dev/null +++ b/dice_score_local.sh @@ -0,0 +1,31 @@ +#!/bin/bash + + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" + computed=${1} + groud_truth=${2} + output=$3 + if [ $# -lt 1 ]; then + echo $0: "usage: "$( basename $0 )" []" + return 1; + fi + + + + + +if ! ( [ -z "${computed}" ] || [ "${computed}" == "null" ] || [ -z "${groud_truth}" ] || [ "${groud_truth}" == "null" ] ); then + + echo "computed: "${computed} + echo "groud_truth: "${groud_truth} + + inputidr=$( dirname ${computed} ) + + [ -z ${output} ] && { output=${inputidr}"/dice_score.txt" ; } + + + python ${SCRIPT_DIR}/dice_score.py ${computed} ${groud_truth} ${output} + + + + +fi diff --git a/download_testset.sh b/download_testset.sh index fcd2186..4d9e9a3 100644 --- a/download_testset.sh +++ b/download_testset.sh @@ -1,6 +1,9 @@ #! /bin/bash tag_list=( ACC PFM MCDs HD ) #pub_id=$1 +output_dir=./'DBB_test' +mkdir -p ${output_dir} for tag in ${tag_list[@]}; do - bl bids download --pub "61b8b6b57ebe1c6fd7f048f2" --tag EMEDEA-PED --tag ${tag} #--output ./DBB_test + mkdir -p ${output_dir}'/'${tag} + bl bids download --pub "61b8b6b57ebe1c6fd7f048f2" --tag EMEDEA-PED --tag ${tag} --output ${output_dir}'/'${tag} done diff --git a/main_local.sh b/main_local.sh new file mode 100644 index 0000000..ff77ea3 --- /dev/null +++ b/main_local.sh @@ -0,0 +1,30 @@ +#! /bin/bash + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" + t1=$1 + mask=$2 + outputdir=$3 + if [ $# -lt 2 ]; then + echo $0: "usage: "$( basename $0 )" []" + exit -1; + fi + + echo "t1: "${t1} + echo "mask: "${mask} + input_dir=$( dirname ${t1} ) + [ -z ${outputdir} ] && { outputdir=${input_dir}"/segmentation" ; } + echo "outputdir: "${outputdir} + + mkdir -p ${outputdir} + output=${outputdir}'/segmentation.nii.gz' + proc_dir=${input_dir}"/proc/" + mkdir -p ${proc_dir} + reference=${SCRIPT_DIR}'/data/IMAGE_0426.nii.gz' + + t1_hm=${proc_dir}'/t1_hm.nii.gz' + ImageMath 3 ${t1_hm} HistogramMatch ${t1} ${reference} + + chkcp_dir=${SCRIPT_DIR} + + python ${SCRIPT_DIR}/predict.py ${t1_hm} ${output} ${chkcp_dir} --mask ${mask} + + cp ${SCRIPT_DIR}'/data/label.json' ${outputdir} diff --git a/predict_testset_local.sh b/predict_testset_local.sh new file mode 100644 index 0000000..a58b55b --- /dev/null +++ b/predict_testset_local.sh @@ -0,0 +1,45 @@ +#! /bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" +testset_dir=$1 +output_dir=$2 +if [ $# -lt 1 ]; then + echo $0: "usage: "$( basename $0 )" []" + return 1; +fi +predict_script=${SCRIPT_DIR}/"main_local.sh" +disce_score_script=${SCRIPT_DIR}/"dice_score_local.sh" +[ -z ${output_dir} ] && { output_dir=${testset_dir}'/bids/derivatives/bl_app_dbb_DisSeg/' ; } +mkdir -p ${output_dir} +for i in $( ls ${testset_dir}/* -d ); do + b_name_i=$( basename ${i} ) + [ "${b_name_i}" == "bids" ] && { continue; } + [ -d ${i} ] || { continue; } + echo ${i} + t1_i=$( ls ${i}'/dt-neuro-anat-t1w.id-'*/'t1.nii.gz' ) + mask_i=$( ls ${i}'/dt-neuro-mask.id-'*/'mask.nii.gz' ) + parc_i=$( ls ${i}'/dt-neuro-parcellation-volume.id-'*/'parc.nii.gz' ) + echo 't1': ${t1_i} + echo 'mask': ${mask_i} + echo 'parc': ${parc_i} + output_dir_i=${output_dir}'/'$( basename ${i} )'/' + echo ${output_dir_i} + mkdir -p ${output_dir_i} + bash ${predict_script} ${t1_i} ${mask_i} ${output_dir_i}'/' + output_seg=${output_dir_i}'/segmentation.nii.gz' + dice_score=${output_dir_i}'/dice_score.txt' + bash ${disce_score_script} ${output_seg} ${parc_i} ${dice_score} + cat ${dice_score} +done + +csv_file=${output_dir}'/dice_score.csv' + +echo "Subject_Id CSF GM WM DGM Brainstem Cerebellum" + +echo "Subject_Id CSF GM WM DGM Brainstem Cerebellum" > ${csv_file} + +for i in $( ls ${output_dir}/* -d ); do + + echo $( basename ${i} ) $( cat ${i}'/dice_score.txt' ) + echo $( basename ${i} ) $( cat ${i}'/dice_score.txt' ) >> ${csv_file} + +done diff --git a/run_test.sh b/run_test.sh index 671e8d4..a47f8d4 100644 --- a/run_test.sh +++ b/run_test.sh @@ -2,5 +2,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" project_id='60a14ca503bcad0ad27cada9' outputdir=$1 +download_dir=./'DBB_test' bash ${SCRIPT_DIR}/download_testset.sh -bash ${SCRIPT_DIR}/predict_testset.sh proj-${project_id} ${outputdir} +mkdir -p ${outputdir} +tag_list=( ACC PFM MCDs HD ) +for tag in ${tag_list[@]}; do + bash ${SCRIPT_DIR}/predict_testset.sh ${download_dir}'/'${tag}'/'proj-${project_id} ${outputdir}'/'${tag} +done diff --git a/run_test_local.sh b/run_test_local.sh new file mode 100644 index 0000000..9dfe1ee --- /dev/null +++ b/run_test_local.sh @@ -0,0 +1,11 @@ +#! /bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/" +project_id='60a14ca503bcad0ad27cada9' +outputdir=$1 +download_dir=./'DBB_test' +bash ${SCRIPT_DIR}/download_testset.sh +mkdir -p ${outputdir} +tag_list=( ACC PFM MCDs HD ) +for tag in ${tag_list[@]}; do + bash ${SCRIPT_DIR}/predict_testset_local.sh ${download_dir}'/'${tag}'/'proj-${project_id} ${outputdir}'/'${tag} +done