procedure ctrcoo (intab,outab,image) string intab ="" {prompt="Input coordinate file"} string outab ="" {prompt="Output coordinate file"} string image ="" {prompt="Image containing the objects"} int cntrbox =7 {prompt="Size of centering box in pixels"} bool redispl =yes {prompt="Redisplay the image first?"} bool verbose =yes {prompt="Print recentered coordinates?"} # @(#)task ctrcoo Author: R.A. Jansen -- Jun 19 2000 # @(#) # @(#)Task to fit center positions to objects in an image given initial # @(#)estimates. Only the first two columns of the input coordinate file # @(#)are read. 'Outab' and 'intab' may be the same, in which case the # @(#)input file will be overwritten. # @(#)Uses: 'imexam' to perform the centering. begin string coo, ctr, img, tmpcoo, tmpctr real x, y int cbox, NN coo = intab ctr = outab img = image cbox = 2*int(0.5*cntrbox)+1 tmpcoo = mktemp("tmpctrcoo") tmpctr = mktemp("tmpctrctr") # Check whether the required packages are loaded... if (!defpac("tv")) { error (1,"Please load \"image.tv\" first!") } # Check existence of input and output files... unlearn chkimg chkimg (coo, "access", imtype="file", verbose=yes) if (!chkimg.ok) { return } if ( ctr != coo ) { chkimg (ctr, "noaccess", imtype="file", verbose=yes) if (!chkimg.ok) { return } } # Check existence of input image... chkimg (img, "access", imtype="", verbose=yes) if (!chkimg.ok) { return } img = chkimg.imroot//chkimg.imtype//chkimg.imrpstr if (redispl) { xdisplay (img, z1=0., z2=0., zmode="linear", verbose=no) } # Write a cursor file for 'imexam' ... if (verbose) { print ("Guessed center coordinates:") } list = coo NN = 0 while( fscan(list,x,y) != EOF ) { NN += 1 print (x,y," 205 a", >> tmpcoo) if (verbose) { print ("#"//str(NN)//" xtry="//str(x)//", ytry="//str(y)) } } print ("1. 1. 205 q", >> tmpcoo) # Use 'imexam' to fit object center positions given the provided # estimated positions... imexam (img, 1, img, logfile=tmpctr, keeplog=yes, defkey="a", autoredraw=yes, allframes=yes, nframes=0, ncstat=cbox, nlstat=cbox, graphcur="", imagecur=tmpcoo, wcs="logical", use_display=no, >& "dev$null") # Delete the input file if 'outab'=='intab' ... if ( ctr == coo ) { delete (coo, yes, verify=no) } # Extract the fitted center positions from the log file ... if (verbose) { print ("Recentered coordinates:", ) } list = tmpctr NN = 0 while ( fscan(list,x,y) != EOF ) { NN += 1 if ( NN >= 3 ) { print (x,y, >> ctr) if (verbose) { print ("#"//str(NN-2)//" xcen="//str(x)//", ycen="//str(y)) } } } # Clean-up ... delete (tmpcoo, yes, verify=no, default_acti=yes) delete (tmpctr, yes, verify=no, default_acti=yes) end