#! /bin/csh -f # # # Find phi rotation axis in camera field of view # # set path = ( /programs/kuim/bin $path ) set tempfile = /tmp/axis_tmp$$ # decide which camera we can see through set camera = 1 set old_axis = `cat /data/calibrations/rotation_axis_in_camera${camera}.txt` set beam_height = `awk '{print $2}' /data/calibrations/beam_in_camera${camera}.txt` set fov = `cat /data/calibrations/field_of_view_in_camera${camera}.txt` if("$old_axis" == "") set old_axis = 0.5 if("$beam_height" == "") set beam_height = 0.5 if("$fov" == "") set fov = -0.461 # now take the pictures snap.com phi0.jpg -nodisplay >& /dev/null phi.com by 180 | tail -1 snap.com phi180.jpg -nodisplay >& /dev/null phi.com by -180 | tail -1 & align: echo "aligning images..." foreach file ( phi0.jpg phi180.jpg ) rm -f out.im type -f $file out.im > /dev/null #rm -f $file mv out.im in.im interp -x 512 -y 512 in.im out.im > /dev/null mv out.im in.im gauss -s 3 in.im out.im > /dev/null mv out.im in.im laplacian in.im out.im > /dev/null mv out.im in.im interp -x 704 -y 480 in.im out.im > /dev/null if("$file" =~ *180*) then mv out.im in.im move_image -t 0 0 -s 1 -1 in.im out.im > /dev/null mv out.im in.im # shave 50 pixels off the top and bottom extract -x 0 703 -y 50 430 in.im out.im > /dev/null endif mv out.im `basename ${file} .jpg`.im end # use KUIM for the image alignment set start = `echo $beam_height | awk '{print ($1-0.5)*480+50}'` #echo "start = $start" rm -f out.im align_y -d -n 100 -s 0 $start phi0.im phi180.im out.im >&! ${tempfile}.log if ($status) set BAD set axis = `awk '/^best/{printf "%d", (240-25+$5/2)/480}' ${tempfile}.log` awk '/^dx dy/{print (240-25+$5/2)/480, $NF}' ${tempfile}.log >! scores.log # try to increase precision with a curve fit set plotit = "#" if( $?debug ) set plotit = "" set axis = `sort -n +1 scores.log | awk '{print $1;exit}'` set c = `sort -n +1 scores.log | awk '{print $2;exit}'` set cutoff = `sort -nr +1 scores.log | tail -7 | awk '{print $NF;exit}'` cat << EOF | gnuplot -persist >&! ${tempfile}fit.log a=10000 b=$axis c=$c fit a*(x-b)**2+c 'scores.log' using 1:(\$2<=$cutoff ? \$2:1/0) via a fit a*(x-b)**2+c 'scores.log' using 1:(\$2<=$cutoff ? \$2:1/0) via a,b,c set yrange [*:$cutoff] set xrange [(b-0.02):(b+0.02)] ${plotit}plot 'scores.log', a*(x-b)**2+c EOF #echo "plot 'scores.log'" | gnuplot -persist set fit_axis = `awk '$1=="b" && $2=="="{print $3}' ${tempfile}fit.log | tail -1` rm -f ${tempfile}fit.log fit.log set toofar = `echo $axis $fit_axis | awk '{print (sqrt(($1-$2)^2)>2/480)}'` if( ! $toofar ) set axis = $fit_axis rm -f residual.jpg type -j out.im residual.jpg > /dev/null #display residual.jpg set pix_axis = `echo $axis 480 | awk '{printf "%.1f", $1*$2}'` set pix_beam = `echo "$beam_height 480" | awk '{printf "%.1f", $1*$2}'` set delta = `echo "$beam_height $axis $fov" | awk '{print ($1 - $2)*$NF}'` set del = `echo $delta | awk '{printf "%.3f",$1}'` echo "rotation axis is at y= $pix_axis pixels (${axis})" echo "beam position is at y= $pix_beam pixels (${beam_height})" echo " delta= $del mm" if (! $?BAD) then echo "$axis" >! /data/calibrations/rotation_axis_in_camera${camera}.txt endif # verify this axis visually convert -pen white -fill white -draw "line 0,$pix_axis 704,$pix_axis" phi0.jpg phi0.bmp convert -pen white -fill white -draw "line 0,$pix_axis 704,$pix_axis" phi180.jpg phi180.bmp composite -compose Multiply phi0.bmp phi180.bmp axis.bmp rm -f axis.mgk >& /dev/null mogrify -normalize -rotate 90 axis.bmp if ($?debug) animate -delay 10 phi0.bmp phi180.bmp rm -f phi180.im phi0.im in.im out.im rm -f phi0.jpg phi180.jpg rm -f ${tempfile}.log scores.log >& /dev/null rm -f residual.jpg >& /dev/null set stage = `stage.com | awk '{print $5}'` set newstage = `echo $stage $delta | awk '{printf "%.4f", $1+$2}'` echo "stage.com $newstage" echo "stage.com save" #if (! $?DEBUG) rm -f phi0.bmp phi180.bmp axis.bmp >& /dev/null exit # check out the results? rm -f test.jpg ; type -j out.im test.jpg ; display test.jpg foreach phi ( `awk 'BEGIN{for(i=0;i<=720;i+=10) print i}'` ) phi.com $phi > /dev/null #foreach delta ( -0.1 0.05 0.05 0.05 0.05 ) #sample.com 0 $delta 0 > /dev/null echo -n "$phi " >> find_axis.com | tail -1 | awk '{print $6}' echo -n "$phi " find_axis.com | tail -1 | awk '{print $6}' #end phi.com 0 > /dev/null #sample.com to 0.609 -0.696 -1.000 > /dev/null end