#! /bin/bash # Last edited on 2007-06-30 16:39:18 by stolfi PROG_NAME=${0##*/} PROG_DESC="make a summary picture of real and virtual gauge photos" PROG_HELP=( "${PROG_NAME} \\" "\n {GPREFIX} {RUNTAG} {NFIELDS}" ) PROG_INFO=( "\nNAME" "\n ${PROG_NAME} - ${PROG_DESC}." "\n" "\nSYNOPSIS" "\n export TOOLDIR={TOOLDIR}" "\n ${PROG_HELP[@]}" "\n" "\nDESCRIPTION" "\n Reads the image files produced by extract-gauge-image-set(1)," "\n and makes a single picture showing them side-by-side" "\n" "\n The images displayed are" "\n" "\n {GPREFIX}-{KK}.png - actual gauge photo in light field {KK} (color)." "\n {GPREFIX}-{KK}.fni - actual gauge photo in light field {KK} (gray)." "\n {GPREFIX}-{RUNTAG}-{KK}-msk.fni - lamp-fiting mask for photo {KK}." "\n {GPREFIX}-{RUNTAG}-{KK}-fit.fni - synthetic photo in light field {KK}." "\n {GPREFIX}-{RUNTAG}-{KK}-dif.fni - difference between the two." "\n {GPREFIX}-{RUNTAG}-nrm.fni - fitted normal map." "\n" "\n where {K} ranges from 0 to {NFIELDS-1}. The output is" "\n a single PNG file \"{GPREFIX}-{RUNTAG}-all.png\"." "\nAUTHOR" "\n Created 2006-04-15 by Jorge Stolfi, Unicamp" ) # ---------------------------------------------------------------------- # INTERNAL OPTIONS # ---------------------------------------------------------------------- # COMMAND LINE PARSING # Parse command line switches: while [[ ( $# -ge 1 ) && ( "/$1" =~ "/-.*" ) ]]; do if [[ 1 ]]; then echo "unknown option $1" 1>&2 ; echo -e "usage:\n ${PROG_HELP[@]}" 1>&2 ; exit 1 fi done # Get positional parameters if [[ $# -ge 3 ]]; then gprefix=$1; shift; runtag=$1; shift; nfields=$1; shift; else echo 'wrong number of arguments "'"$1"'" ...' 1>&2 ; echo -e "usage:\n ${PROG_HELP[@]}" 1>&2 ; exit 1 fi # Check for leftover arguments: if [[ $# -ne 0 ]]; then echo 'wrong number of arguments "'"$1"'" ...' 1>&2 ; echo -e "usage:\n ${PROG_HELP[@]}" 1>&2 ; exit 1 fi # END COMMAND LINE PARSING # ---------------------------------------------------------------------- # Temporary file name prefix: tmp=/tmp/$$ # Make the row pictures: rowfiles=( ) for field in `count 0 $(( ${nfields} - 1 )) 1 '%02d'` ; do # Images to show side by side: rgbpng="${gprefix}-${field}.png" lumfni="${gprefix}-${field}.fni" mskfni="${gprefix}-${runtag}-${field}-msk.fni" fitfni="${gprefix}-${runtag}-${field}-fit.fni" diffni="${gprefix}-${runtag}-${field}-dif.fni" # Comversion to PPM/PGM rgbppm="${tmp}-${field}-rgb.ppm" lumpgm="${tmp}-${field}-lum.pgm" mskppm="${tmp}-${field}-msk.ppm" fitpgm="${tmp}-${field}-fit.pgm" difpgm="${tmp}-${field}-dif.pgm" convert ${rgbpng} ${rgbppm} cat ${lumfni} | fni-to-pnm -channel 0 -min 0.0 -max 1.0 > ${lumpgm} cat ${fitfni} | fni-to-pnm -channel 0 -min 0.0 -max 1.0 > ${fitpgm} cat ${diffni} | fni-to-pnm -channel 0 -min -0.25 -max +0.25 > ${difpgm} cat ${mskfni} | \ fni-to-pnm \ -channels 0 1 2 \ -min 0.0 0.0 0.0 \ -max 1.0 1.0 1.0 \ > ${mskppm} # Make a single PPM of the four images side by side: rowppm="${tmp}-${field}-row.ppm" pnmcat -lr ${rgbppm} ${lumpgm} ${mskppm} ${fitpgm} ${difpgm} > ${rowppm} rowfiles=( ${rowfiles[@]} ${rowppm} ) # Cleanup: rm -f ${rgbppm} ${lumpgm} ${mskppm} ${fitpgm} ${difpgm} done # Create a large pic of the normal map: nrmfni="${gprefix}-${runtag}-nrm.fni" nrmppm="${tmp}-nrm.ppm" cat ${nrmfni} \ | fni-to-pnm \ -channels 0 1 2 \ -min -1.0 -1.0 -1.0 \ -max +1.0 +1.0 +1.0 \ > ${nrmppm} # Stack the rows top to bottom: allpng="${gprefix}-${runtag}-all.png" pnmcat -tb ${nrmppm} ${rowfiles[@]} \ | convert PPM:- ${allpng} # Cleanup: rm -f ${nrmppm} ${rowfiles[@]}