#!/bin/bash if [ -z "$1" ]; then cat < : Specify one subject ID. -l : Specify a file list with the subject IDs, one per line. -m : Specify a surface file (pial, white, inflated, sphere, etc). -p : Specify a parcellation to load (aparc, a2009s, a2005s). -d : Specify the directory to save the resulting HTML page. -c : Run also for curv. -u : Run also for sulc. -t : Run also for thickness. -y : Run also for myelin maps -v : Run also for volumes (aseg + overlaid surfaces). -g : Run also for the gwc * Important: This script requires ImageMagick (command 'convert'), and that the FreeSurfer variable SUBJECTS_DIR has been set. _____________________________________ Anderson M. Winkler Yale University / Institute of Living Jan/2010 http://brainder.org EOU exit 1 fi # Check and accept the arguments DOASEG="N" DOSURF="N" DOCURV="N" DOSULC="N" DOTHCK="N" DOGWC="N" while getopts 's:l:m:p:d:cutygv' OPTION do case ${OPTION} in s) SUBJ_LIST="${SUBJ_LIST} ${OPTARG}" ;; l) SUBJ_LIST="${SUBJ_LIST} $(cat ${OPTARG})" ;; m) MESH_LIST="${MESH_LIST} ${OPTARG}" ;; p) PARC_LIST="${PARC_LIST} ${OPTARG}" ; DOSURF="Y" ;; d) HTML_DIR="${OPTARG}" ;; c) DOSURF="Y" ; DOCURV="Y" ; PARC_LIST="${PARC_LIST} curv" ;; u) DOSURF="Y" ; DOSULC="Y" ; PARC_LIST="${PARC_LIST} sulc" ;; t) DOSURF="Y" ; DOTHCK="Y" ; PARC_LIST="${PARC_LIST} thickness" ;; y) DOSURF="Y" ; DOMYEL="Y" ; PARC_LIST="${PARC_LIST} myelin" ;; g) DOSURF="Y" ; DOGWC="Y" ; PARC_LIST="${PARC_LIST} gwc" ;; v) DOASEG="Y" ;; esac done if [ "x${HTML_DIR}" == "x" ] ; then echo "Output directory not specified" exit 1 ; fi # Cropping, format conversion and thumbnail generation if [[ ${DOSURF} == "Y" ]] ; then for m in ${MESH_LIST} ; do echo "Preparing ${m} images" mkdir -p ${HTML_DIR}/${m}/images ${HTML_DIR}/${m}/thumbnails [ "${m}" == "pial" ] || [ "${m}" == "white" ] && sizimg="410x300" && sizthm="205x150" [ "${m}" == "inflated" ] && sizimg="610x400" && sizthm="305x200" [ "${m}" == "sphere" ] && sizimg="440x440" && sizthm="220x220" for s in ${SUBJ_LIST} ; do echo ${s} for p in ${PARC_LIST} ; do for img in ${SUBJECTS_DIR}/${s}/shots/${s}_*h_${m}_${p}_*.tif ; do bimg=$(basename ${img} .tif) convert ${img} -trim -background black -gravity center -extent ${sizimg} -format png ${HTML_DIR}/${m}/images/${bimg}.png convert ${HTML_DIR}/${m}/images/${bimg}.png -resize ${sizthm} -depth 8 -colors 256 ${HTML_DIR}/${m}/thumbnails/${bimg}.png done done if [[ ${DOCURV} == "Y" ]] || [[ ${DOSULC} == "Y" ]] || [[ ${DOTHCK} == "Y" ]] || [[ ${DOMYEL} == "Y" ]]; then for img in ${SUBJECTS_DIR}/${s}/shots/${s}_*h_${m}_*_*.tif ; do bimg=$(basename ${img} .tif) convert ${img} -trim -background black -gravity center -extent ${sizimg} -format png ${HTML_DIR}/${m}/images/${bimg}.png convert ${HTML_DIR}/${m}/images/${bimg}.png -resize ${sizthm} -depth 8 -colors 256 ${HTML_DIR}/${m}/thumbnails/${bimg}.png done fi done done fi if [[ ${DOASEG} == "Y" ]] ; then sizimg="400x400" sizthm="200x200" for m in aseg surfaces ; do echo "Preparing ${m} images" for s in ${SUBJ_LIST} ; do echo ${s} mkdir -p ${HTML_DIR}/${m}/images ${HTML_DIR}/${m}/thumbnails for img in ${SUBJECTS_DIR}/${s}/shots/*_${m}_*.tif ; do bimg=$(basename ${img} .tif) convert ${img} -shave 12x12 -trim -background black -gravity center -extent ${sizimg} -format png ${HTML_DIR}/${m}/images/${bimg}.png convert ${HTML_DIR}/${m}/images/${bimg}.png -resize ${sizthm} -depth 8 -colors 256 ${HTML_DIR}/${m}/thumbnails/${bimg}.png done done done fi # Create the HTML file echo "Creating HTML pages" if [[ ${DOSURF} == "Y" ]] ; then for m in ${MESH_LIST} ; do for p in ${PARC_LIST} ; do htmlfile=${HTML_DIR}/${m}/${m}_${p}.html echo "Surface Results (${m}, ${p})" > ${htmlfile} for s in ${SUBJ_LIST} ; do echo "" >> ${htmlfile} for view in lat med sup inf ; do for h in lh rh ; do echo "" >> ${htmlfile} done ; done echo "" >> ${htmlfile} done echo "
" >> ${htmlfile} done done fi if [[ ${DOASEG} == "Y" ]] ; then for m in aseg surfaces ; do htmlfile=${HTML_DIR}/${m}/${m}.html echo "Volume Results (${m}, ${p})" > ${htmlfile} for s in ${SUBJ_LIST} ; do echo "" >> ${htmlfile} for view in tra cor sag ; do if [[ ${view} == "tra" ]] ; then slicelist="118 128 138" elif [[ ${view} == "cor" ]] ; then slicelist="068 088 098 108 118 128 138 148 158 168 188" elif [[ ${view} == "sag" ]] ; then slicelist="088 168" fi for sl in ${slicelist} ; do echo "" >> ${htmlfile} done done echo "" >> ${htmlfile} done echo "
" >> ${htmlfile} done fi # Create the index.html echo "Inspect results

Inspect results


" > ${HTML_DIR}/index.html for m in ${MESH_LIST} ; do for p in ${PARC_LIST} ; do echo "

${m}: ${p}

" >> ${HTML_DIR}/index.html done done if [[ ${DOASEG} == "Y" ]] ; then for m in aseg surfaces ; do echo "

volumes: ${m}

" >> ${HTML_DIR}/index.html done fi echo "" >> ${HTML_DIR}/index.html echo "Done!"