Skip to content

Commit

Permalink
SAMPLE DATA: Removed files and updated BIDS dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastientourbier committed May 10, 2019
1 parent 5ec8afe commit 64bc529
Show file tree
Hide file tree
Showing 34 changed files with 114 additions and 24 deletions.
2 changes: 1 addition & 1 deletion data/code/batch_list.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sub-01 0.75 0.01 run-01_scans
sub-01 ses-01 0.75 0.01
3 changes: 0 additions & 3 deletions data/code/sub-01_run-01_scans.txt

This file was deleted.

58 changes: 45 additions & 13 deletions data/code/superresolution_batch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh
# usage:
# sh generic_script_to_run_superresolution.sh /path/to/batch_list.txt
# sh superresolution_batch.sh /path/to/batch_list.txt v1.0.0
#
# Author: Sebastien Tourbier
#
###################################################################

# Get the directory where the script is stored,
# which is supposed to be in the code folder of the dataset root directory)
Expand All @@ -13,31 +17,55 @@ DATASET_DIR="$(dirname "${SCRIPT_DIR}")"

echo "Dataset directory : $DATASET_DIR"

VERSION_TAG=$2

#from each line of the subject_parameters.txt given as input
while read -r line
do
#Extract PATIENT, LAMBDA_TV and DELTA_T and the scan list sub-01_run-01_scans.txt
#Extract PATIENT, LAMBDA_TV and DELTA_T and the scan list sub-01_ses-01_scans.txt
set -- $line
PATIENT=$1
LAMBDA_TV=$2
DELTA_T=$3
SCANS_LIST="${PATIENT}_${4}.txt"
LAMBDA_TV=$3
DELTA_T=$4
RECON_SESSION=$2
SCANS_LIST="${PATIENT}_${RECON_SESSION}_scans.txt"

echo "> Process subject ${PATIENT} with lambda_tv = ${LAMBDA_TV} and delta_t = ${DELTA_T}"

PATIENT_DIR="$DATASET_DIR/${PATIENT}"
echo " ... Subject directory : ${PATIENT_DIR}"

# Get the number of scans in the list
# Can be used to differentiate output folders
# i.e. line RESULTS="derivatives/mialsrtk/$PATIENT/${RECON_SESSION}" would become
# RESULTS="derivatives/mialsrtk_scans-${VOLS}/$PATIENT/${RECON_SESSION}"

VOLS=0
while read -r line
do
VOLS=$((VOLS+1))
done < "${DATASET_DIR}/code/${SCANS_LIST}"

echo " ... Number of scans : ${VOLS}"
echo

# Create the output directory for results (if not existing).
# run-XX is used to identify different list of scans:
# sub-01_run-01_scans.txt, sub-01_run-02_scans.txt, ..., sub-01_run-XX_scans.txt
# here I am just using sub-01_run-01_scans.txt but you can think as I am looping over
# the different calls while reading the batch_list.txt file,
# you could similarly loop over different list of scans.
# The final superesolution is saved in derivatives/mialsrtk_tv-${LAMBDA_TV}_dt-${DELTA_T}_run-01/$PATIENT/anat folder
# sub-01_ses-01_scans.txt, sub-01_ses-02_scans.txt, ..., sub-01_ses-XX_scans.txt
# The final superesolution is saved in derivatives/mialsrtk/$PATIENT/ses-XX/anat folder
# All intermediate outputs are saved in a tmp folder (see below).

if [ ! -d "${DATASET_DIR}/derivatives/mialsrtk" ]; then
mkdir -p "${DATASET_DIR}/derivatives/mialsrtk";
echo " * Folder ${DATASET_DIR}/derivatives/mialsrtk created"
fi

if [ ! -f "${DATASET_DIR}/derivatives/mialsrtk/dataset_description.json" ];
then
sh ${DATASET_DIR}/code/create_dataset_description_json.sh "${DATASET_DIR}/derivatives/mialsrtk/dataset_description.json" "$VERSION_TAG"
fi

RESULTS="derivatives/mialsrtk_tv-${LAMBDA_TV}_dt-${DELTA_T}_run-01/$PATIENT"
RESULTS="derivatives/mialsrtk/$PATIENT/${RECON_SESSION}"
echo " ... Reconstruction tmp directory: ${DATASET_DIR}/${RESULTS}"
if [ ! -d "${DATASET_DIR}/${RESULTS}" ]; then
mkdir -p "${DATASET_DIR}/${RESULTS}";
Expand All @@ -51,6 +79,10 @@ while read -r line
mkdir -p "${DATASET_DIR}/${RESULTS}/anat";
echo " * Folder ${DATASET_DIR}/${RESULTS}/anat created"
fi
if [ ! -d "${DATASET_DIR}/${RESULTS}/xfm" ]; then
mkdir -p "${DATASET_DIR}/${RESULTS}/xfm";
echo " * Folder ${DATASET_DIR}/${RESULTS}/xfm created"
fi

PATIENT_MASK_DIR="derivatives/manual_masks/$PATIENT"

Expand All @@ -65,8 +97,8 @@ while read -r line
--env LAMBDA_TV="$LAMBDA_TV "\
--env PATIENT_DIR="/fetaldata/${PATIENT}" \
--env PATIENT_MASK_DIR="/fetaldata/${PATIENT_MASK_DIR}/anat" \
--env RESULTS="/fetaldata/${RESULTS}/tmp" \
-t sebastientourbier/mialsuperresolutiontoolkit:v1.1.0 \
--env RESULTS="/fetaldata/${RESULTS}" \
-t sebastientourbier/mialsuperresolutiontoolkit:"$VERSION_TAG" \
"/fetaldata/code/${SCANS_LIST}"


Expand Down
75 changes: 68 additions & 7 deletions data/code/superresolution_pipeline.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/sh
#! Script: Brain image reconstruction / Brain superresolution image using BTK
# Run with log saved: sh reconstruction.sh > reconstruction_original_images.log
#
# Script: Superresolution pipeline for fetal brain MRI
#
# Usage: Run with log saved: sh superresolution_pipeline.sh list_of_scans.txt > reconstruction_original_images.log
#
# Author: Sebastien Tourbier
#
########################################################################################################################

#Tune the number of cores used by the OpenMP library for multi-threading purposes
export OMP_NUM_THREADS=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

ANAT_DIR=$RESULTS/anat
XFM_DIR=$RESULTS/xfm
RESULTS=$RESULTS/tmp

echo
echo "-----------------------------------------------"
echo
Expand Down Expand Up @@ -295,12 +306,62 @@ do
ITER=$((ITER+1))

done
LAST_ITER=1


# Extract absolute path of the folder containing the scripts (i.e. /fetaldata/code)
CODE_DIR="$(dirname "$0")"
CODE_DIR="$(readlink -f $CODE_DIR)"

echo "Dataset code directory: ${CODE_DIR}"

# Move the preprocessed input scans to anat and their associated slice-to-volume transform and
# create their respective json file (BIDS Common Derivatives RC1)

SOURCES=""
while read -r line
do
set -- $line
stack=$1

# Copy and rename the transform and the image
cp "$RESULTS/${stack}_transform_${VOLS}V_${LAST_ITER}.txt" "${XFM_DIR}/${stack}_from-orig_to-SDI_mode-image_xfm.txt"
cp "$RESULTS/${stack}_uni_bcorr_reo_iteration_${LAST_ITER}_histnorm.nii.gz" "${ANAT_DIR}/${stack}_preproc.nii.gz"

# Create the BIDS json sidecar
sh ${CODE_DIR}/create_scan_preproc_json.sh "${ANAT_DIR}/${stack}_preproc.json" "${PATIENT_DIR}/${stack}.nii.gz"

SOURCES="${SOURCES} \"${ANAT_DIR}/${stack}_preproc.nii.gz\", \"${XFM_DIR}/${stack}_from-orig_to-SDI_mode-image_xfm.txt\" ,"

done < "$SCANS"

FINAL_OUTPUT_DIR="$(dirname "$RESULTS")/anat"
echo "Copy final outputs to ${FINAL_OUTPUT_DIR}"
cp "$RESULTS/SDI_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}.nii.gz" "${FINAL_OUTPUT_DIR}/${PATIENT}_rec-SDI_T2w.nii.gz"
cp "$RESULTS/SRTV_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}.nii.gz" "${FINAL_OUTPUT_DIR}/${PATIENT}_rec-SR_T2w.nii.gz"
cp "$RESULTS/SRTV_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}_masked.nii.gz" "${FINAL_OUTPUT_DIR}/${PATIENT}_rec-SR_desc-masked_T2w.nii.gz"
# Move the reconstructed images to anat and create the json file (BIDS Common Derivatives RC1)

ANAT_DIR="$(dirname "$RESULTS")/anat"
echo "Copy final outputs to ${ANAT_DIR}"
cp "$RESULTS/SDI_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}.nii.gz" "${ANAT_DIR}/${PATIENT}_rec-SDI_T2w.nii.gz"
cp "$RESULTS/SRTV_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}.nii.gz" "${ANAT_DIR}/${PATIENT}_rec-SR_T2w.nii.gz"
cp "$RESULTS/SRTV_${PATIENT}_${VOLS}V_rad${RAD_DILATION}_it${LAST_ITER}_masked.nii.gz" "${ANAT_DIR}/${PATIENT}_rec-SR_desc-masked_T2w.nii.gz"


# Create the json file for the super-resolution images
OUTPUT_JSON="${ANAT_DIR}/${PATIENT}_rec-SR.json"
(
cat <<EOF
{
"Description": "Isotropic high-resolution image reconstructed using the Total-Variation Super-Resolution algorithm provided by MIALSRTK",
"Sources": [${SOURCES}],
"CustomMetaData": {
"Number of scans used": $VOLS,
"TV regularization weight lambda": ${LAMBDA_TV},
"Optimization time step": ${DELTA_T},
"Primal/dual loops": $LOOPS,
"Number of pipeline iterations" : ${LAST_ITER}
}
}
EOF
) > $OUTPUT_JSON

echo
echo "##########################################################################################################################"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed data/sub-01/sub-01_run-01_T2w.nii.gz
Binary file not shown.
Binary file removed data/sub-01/sub-01_run-02_T2w.nii.gz
Binary file not shown.
Binary file removed data/sub-01/sub-01_run-03_T2w.nii.gz
Binary file not shown.

0 comments on commit 64bc529

Please sign in to comment.