#! /bin/bash # Last edited on 2008-02-04 20:31:31 by stolfi usage="${0##*/} KIND/BATCH/IMG.jpg < RAWPOINTS > FINEPOINTS " # Reads the image IMG.jpg and looks for line crossings # near the pixel positions specified in RAWPOINTS. # Writes the refined positions (with sub-pixel accuracy) to # file FINEPOINTS. if [ $# -ne 1 ]; then echo "usage: ${usage}"; exit 1; fi imgfile="$1"; shift batroot="${STOLFIHOME}/projects/fragments/IAB-2002/raw-sorted" tools="${STOLFIHOME}/projects/fragments/IAB-2002/tools" if [ ! -e ${imgfile} ]; then echo "image ${imgfile} doesnt exist"; exit 1; fi; tmp="/tmp/$$" # tmpimgnorm=${tmp}-norm.pgm tmpimgnorm=/tmp/15245-img.pgm tmpimgshow=${tmp}-show.jpg tmpinpfile=${tmp}.grpts tmprawfile=${tmp}-raw.pts tmprawcmds=${tmp}-raw.pcmds tmpfinfile=${tmp}-fin.pts tmpfincmds=${tmp}-fin.pcmds # convert ${batroot}/${imgfile} PPM:- \ # | ppmtopgm \ # | pnmdepth 255 \ # | pgmlocnorm -radius 10 -noise 9 \ # > ${tmpimgnorm} # Save input file, without comments: cat \ | gawk \ ' //{ gsub(/ *[#].*$/,"",$0); } \ /./{ \ if (NF != 6) { print "bad raw pts" > "/dev/stderr"; exit 1; } \ print $1, $2, $3, $4, $5, $6; \ } \ ' \ > ${tmpinpfile} if [ ! -e ${tmpinpfile} ]; then echo "file ${tmpinpfile} not created"; exit 1; fi; # Prepare input file for pgmfindcross: cat ${tmpinpfile} \ | gawk '/./{ print $1, $2, 0, 90; }' \ > ${tmprawfile} # Refine crossings: cat ${tmprawfile} \ | pgmfindcross \ -darklines \ -radius 8 -maxdisp 20 -maxrot 10 -linewd 1.5 \ ${tmpimgnorm} \ > ${tmpfinfile} # Join refined crossings with input data, and output selected fields: paste --delimiters=' ' ${tmpfinfile} ${tmpinpfile} \ | gawk \ ' /./{ \ printf " %6s %6s %6s %6s %6s %6s\n", \ $1, $2, $7, $8, $9, $10; \ } \ ' # Plot original crossings: ${tools}/draw-crossings \ -v scale=1.0 -v radius=2 \ < ${tmprawfile} > ${tmprawcmds} if [ ! -e ${tmprawcmds} ]; then echo "file ${tmprawcmds} not created"; exit 1; fi; # Plot refined crossings: ${tools}/draw-crossings \ -v scale=1.0 -v radius=3 \ < ${tmpfinfile} > ${tmpfincmds} if [ ! -e ${tmpfincmds} ]; then echo "file ${tmpfincmds} not created"; exit 1; fi; # Generate image showing the crossings: convert -quality 90 \ -font '-*-courier-medium-r-*-*-10-*-*-*-*-*-iso8859-*' \ -fill red -draw "@${tmprawcmds}" \ -fill yellow -draw "@${tmpfincmds}" \ ${tmpimgnorm} ${tmpimgshow} if [ ! -e ${tmpimgshow} ]; then echo "image ${tmpimgshow} doesnt exist"; exit 1; fi; display ${tmpimgshow} # rm -f ${tmpimgnorm} ${tmprawfile} ${tmpfinfile} # rm -f ${tmprawcmds} ${tmpfincmds} ${tmpimgshow}