#! /bin/tcsh -f # Last edited on 2002-08-23 15:02:46 by hcgl set cmd = "$0"; set cmd = "${cmd:t}" set usage = "${cmd} IMG DXA DYA MGA DXB DYB MGB DXC DYC MGC" # Combines three colorp hotometric stereo images ${IMG}a, ${IMG}b, ${IMG}c # (same camera, different lights) and extracts three directional indicators # u,v,w for each pixel. These are related to the local surface normals # by an unknown linear transformation. # # When combining the images, applies (small) translation by (-DX,-DY) # and a uniform scaling by a factor MG to each image. if ( $#argv != 10 ) then echo "usage: ${usage}"; exit 1 endif set img = "$1"; shift; set dxa = "$1"; shift; set dya = "$1"; shift; set mga = "$1"; shift; set dxb = "$1"; shift; set dyb = "$1"; shift; set mgb = "$1"; shift; set dxc = "$1"; shift; set dyc = "$1"; shift; set mgc = "$1"; shift; set wa = 0.3333333 set wb = 0.3333333 set wc = 0.3333333 set tmp = /tmp/$$ echo "averaging ${img}{a,b,c}.jpg -> ${img}n.jpg" gawk \ -v dxa=${dxa} -v dxb=${dxb} -v dxc=${dxc} \ -v dya=${dya} -v dyb=${dyb} -v dyc=${dyc} \ -v mga=${mga} -v mgb=${mgb} -v mgc=${mgc} \ ' BEGIN{ \ wxa=2048*mga-dxa; wxb=2048*mgb-dxb; wxc=2048*mgc-dxc; \ wxm=(wxa ${tmp}.size set sz = ( `cat ${tmp}.size` ) echo "image size = ${sz}" cat ${img}a.jpg \ | convert jpg:- ppm:- \ | ppmtopgm \ | pnmscale ${mga} \ | pnmcut ${dxa} ${dya} ${sz[1]} ${sz[2]} \ | pgmnorm -wpercent 5 \ > ${tmp}a.pgm cat ${img}b.jpg \ | convert jpg:- ppm:- \ | ppmtopgm \ | pnmscale ${mgb} \ | pnmcut ${dxb} ${dyb} ${sz[1]} ${sz[2]} \ | pgmnorm -wpercent 5 \ > ${tmp}b.pgm cat ${img}c.jpg \ | convert jpg:- ppm:- \ | ppmtopgm \ | pnmscale ${mgc} \ | pnmcut ${dxc} ${dyc} ${sz[1]} ${sz[2]} \ | pgmnorm -wpercent 5 \ > ${tmp}c.pgm pnmxarith -mix ${wa} ${wb} ${tmp}a.pgm ${tmp}b.pgm > ${tmp}ab.pgm pnmxarith -mix 1.000 ${wc} ${tmp}ab.pgm ${tmp}c.pgm > ${tmp}m.pgm pnmxarith -divide -scale 0.3333333 ${tmp}a.pgm ${tmp}m.pgm > ${tmp}aq.pgm pnmxarith -divide -scale 0.3333333 ${tmp}b.pgm ${tmp}m.pgm > ${tmp}bq.pgm pnmxarith -divide -scale 0.3333333 ${tmp}c.pgm ${tmp}m.pgm > ${tmp}cq.pgm rgb3toppm ${tmp}aq.pgm ${tmp}bq.pgm ${tmp}cq.pgm > ${tmp}n.ppm convert -quality 98 ${tmp}n.ppm ${img}n.jpg /bin/rm -f ${tmp}*.ppm ${tmp}*.pgm