pro recenter, imgs, xold, yold, xnew, ynew, $ cbox = cbox, maxpix = maxpix, $ badpix = badpix, mask = mask, $ wait = wait, nodisplay = nodisplay, silent = silent,errors=errors,errin=errin ;+ ;pro recenter, imgs, xold, yold, xnew, ynew, $ ; cbox = cbox, maxpix = maxpix, $ ; badpix = badpix, mask = mask, $ ; wait = wait, nodisplay = nodisplay, silent = silent ; ; ; PURPOSE: ; given an array of images and initial guesses for registration, ; calculate final offsets using IMCENTERF ; ; HISTORY: ; 05/04/97 MCL ; ; old coordinates can be scalars or vectors ; 07/08/97 MCL ; ; added /maxpix option ; 07/07/98 MCL ; ; prints stats for shifts ; 08/10/98 MCL ; ; set /fix for imcut, so objects near the edge are displayed ok ; 10/09/98 MCL ; ; added 'wait' parm - can specify delay between frames ; 07/07/99 MCL ; ; draws the centering box on the displayed zoom area ; 09/29/00 MCL ; ; worked for 1 image ; added /silent ; 06/11/01 MCL ; ; Fixed return-without-stop on incorrect arguments. That's dangerous. ; 06/21/02 MDP ; ; Added errors parameter. 2004-04-08 MDP ;- ;########################################################################### ; ; LICENSE ; ; This software is OSI Certified Open Source Software. ; OSI Certified is a certification mark of the Open Source Initiative. ; ; Copyright © 1997-2003 by Michael C. Liu & Marshall D. Perrin ; ; This software is provided "as-is", without any express or ; implied warranty. In no event will the authors be held liable ; for any damages arising from the use of this software. ; ; Permission is granted to anyone to use this software for any ; purpose, including commercial applications, and to alter it and ; redistribute it freely, subject to the following restrictions: ; ; 1. The origin of this software must not be misrepresented; you must ; not claim you wrote the original software. If you use this software ; in a product, an acknowledgment in the product documentation ; would be appreciated, but is not required. ; ; 2. Altered source versions must be plainly marked as such, and must ; not be misrepresented as being the original software. ; ; 3. This notice may not be removed or altered from any source distribution. ; ; For more information on Open Source Software, visit the Open Source ; web site: http://www.opensource.org. ; ;########################################################################### message,"NO! Don't use recenter.pro, it's crap!" stop if not(keyword_set(wait)) then wait = 0.9 if n_params() lt 5 then begin message, 'pro recenter, imgs, xold, yold, xnew, ynew,' $ +' [cbox=],[maxpix],' $ +' [badpix=],[mask=],[wait=],[nodisplay]' endif sz = size(imgs) if not(keyword_set(badpix)) then badpix = bytarr(sz(1), sz(2)) + 1B if keyword_set(maxpix) then message, 'using /maxpix to recenter', /info ; sanity check if (sz(0) eq 2) then nimgs = 1 $ else nimgs = sz(3) nx = n_elements(xold) ny = n_elements(yold) if keyword_set(mask) then begin szm = size(mask) nmask = szm(3) endif else $ nmask = nimgs if ((nimgs ne nx) and (nx ne 1)) $ or ((nimgs ne ny) and (ny ne 1)) or (nimgs ne nmask) then begin message, 'image array(s) & offsets are not the same length', /info stop endif ; make copy of initial guesses if (nx eq 1) then xol = fltarr(nimgs)+xold else xol = xold if (ny eq 1) then yol = fltarr(nimgs)+yold else yol = yold ; init xnew = fltarr(nimgs) ynew = fltarr(nimgs) if not(keyword_set(nodisplay)) then begin win, 0, tit = 'IDL 0: recenter.pro' win, 1, tit = 'IDL 1: recenter.pro (zoom)' endif ; now loop through images for i = 0, nimgs-1 do begin ; generate bad pixel mask if keyword_set(mask) then $ bp = badpix * mask(*, *, i) $ else $ bp = badpix if (xol(i) ne -999) then begin imcenterf, imgs(*, *, i), xol(i), yol(i), xx, yy, $ cbox = cbox, maxpix = maxpix, badpix = bp, /silent,$ errin=errin,errors=errors xnew(i) = xx ynew(i) = yy ; check centering using Goddard 'cntrd.pro' function with FWHM=4 if (xnew(i)-4) ge 0 and (xnew(i)+4) lt (sz(1)-1) and $ (ynew(i)-4) ge 0 and (ynew(i)+4) lt (sz(2)-1) then begin cntrd, imgs(*, *, i), xnew(i), ynew(i), xnew2, ynew2, 4 if (xnew(i)-(xnew2)+ynew(i)-ynew2 gt 1.0) then $ print, ' image ', strc(i), ' diff w/CNTRD: ', $ printcoo((xnew(i)-xnew2), (ynew(i)-ynew2)) endif if not(keyword_set(nodisplay)) then begin ; overlay cross and box wset, 0 display2, imgs(*, *, i), /silent, $ tit = 'image '+strc(i)+', CBOX='+strc(cbox) plots, [xx-2*cbox, xx+2*cbox, xx, xx, xx], $ [yy, yy, yy, yy+2*cbox, yy-2*cbox], /data, color = 1 tvbox, cbox, xx, yy, 0, /data ; display zoom region, w/bad pixels fixed ; and with centering box overlayed wset, 1 cut = imcut(imgs(*, *, i), 4*CBOX+1, xx, yy, /silent, /fix) bpcut = imcut(bp, 4*CBOX+1, xx, yy, /silent, /fix) fixpix, cut, bpcut, cutfix, /silent display2, cutfix, /tv, /silent, $ tit = 'image '+strc(i), $ xtit = 'zoom size = 4*CBOX', ytit = 'zoom size = 4*CBOX' tvbox, CBOX, 2*CBOX+ (xx-round(xx)), 2*CBOX+(yy-round(yy)), /data, thick = 2 wait, wait endif endif else begin xnew = xol ynew = yol endelse endfor ; print shifts & their stats if not(keyword_set(silent)) then begin print print, form = '(5X,A5,2(A10))', 'image', 'xnew-xold', 'ynew-yold' print, form = '(5X,A5,2(A10))', '-----', '---------', '---------' for i = 0, nimgs-1 do $ print, form = '(5X,A3,2(5X,F5.1))', $ strc(i), xnew(i)-xol(i), ynew(i)-yol(i) endif ; print stats if (nimgs gt 1) and not(keyword_set(silent)) then begin print, '== stats for (xnew - xold) ==' stat, xnew-xol print, '== stats for (ynew - yold) ==' stat, ynew-yol endif else begin xnew = xnew(0) ynew = ynew(0) endelse end