pro newcentroid, array, c, r, ccntr, rcntr ; WARNING: This procedure may return a centroid location outside the bounds ; of the array. ; Find second brightest pixel among pixels surrounding array(c,r) d = fltarr(3,3) for di = 0,2 do begin for dj = 0,2 do begin d(di,dj) = 1000000. endfor endfor s = size(array) i1 = c-1 if (c eq 0) then i1 = c i2 = c+1 if (c eq s(1)-1) then i2 = c j1 = r-1 if (r eq 0) then j1 = r j2 = r+1 if (r eq s(2)-1) then j2 = r di = 0 for i = i1, i2 do begin dj = 0 for j = j1, j2 do begin d(di,dj) = array(c,r) - array(i,j) dj = dj +1 endfor di = di + 1 endfor for di = 0,1 do begin for dj = 0,1 do begin if (d(di,dj) eq 0) then d(di,dj) = 1000000. endfor endfor dmax = min(d,dindx) if (c eq 0) then cindx = c + (dindx mod 3) else cindx = c + (dindx mod 3) -1 if (r eq 0) then rindx = r + (dindx / 3) else rindx = r + (dindx / 3) -1 ; Find the coordinates (ccntr,rcntr) of the maximum point of the parabola ; passing through the brightest and second brightest pixels, and two pixels on ; either side. case (c-cindx) of -1: begin xx = [-1, 0, 1, 2] case (r-rindx) of -1: if (r eq 0) or (c eq 0) then begin xx = [0, 1, 2] find_max, 3, 0, array, c, r, xx, sqrt(2.0), ccntr, rcntr endif else begin find_max, 4, 0, array, c, r, xx, sqrt(2.0), ccntr, rcntr endelse 0: if (c eq 0) then begin xx = [0, 1, 2] find_max, 3, 2, array, c, r, xx, 1, ccntr, rcntr endif else begin find_max, 4, 2, array, c, r, xx, 1, ccntr, rcntr endelse 1: if (r eq s(2)-1) or (c eq 0) then begin xx = [0, 1, 2] find_max, 3, 1, array, c, r, xx, sqrt(2.0), ccntr, rcntr endif else begin find_max, 4, 1, array, c, r, xx, sqrt(2.0), ccntr, rcntr endelse endcase end ; (c-cindx) = -1 0: begin case (r-rindx) of -1: if (r eq 0) then begin xx = [0, 1, 2] find_max, 3, 3, array, c, r, xx, 1, ccntr, rcntr endif else begin xx = [-1, 0, 1, 2] find_max, 4, 3, array, c, r, xx, 1, ccntr, rcntr endelse 0: begin print, ' Error - the second brightest pixel cannot be the same as the brightest pixel' stop end 1: if (r eq s(2)-1) then begin xx = [-2, -1, 0] find_max, 3, 3, array, c, r, xx, 1, ccntr, rcntr endif else begin xx = [-2, -1, 0, 1] find_max, 4, 3, array, c, r, xx, 1, ccntr, rcntr endelse endcase end ; (c-cindx) = 0 1: begin xx = [-2, -1, 0, 1] case (r-rindx) of -1: if (r eq 0) or (c eq s(1)-1) then begin xx = [-2, -1, 0] find_max, 3, 1, array, c, r, xx, sqrt(2.0), ccntr, rcntr endif else begin find_max, 4, 1, array, c, r, xx, sqrt(2.0), ccntr, rcntr endelse 0: if (c eq s(1)-1) then begin xx = [-2, -1, 0] find_max, 3, 2, array, c, r, xx, 1, ccntr, rcntr endif else begin find_max, 4, 2, array, c, r, xx, 1, ccntr, rcntr endelse 1: if (r eq s(2)-1) or (c eq s(1)-1) then begin xx = [-2, -1, 0] find_max, 3, 0, array, c, r, xx, sqrt(2.0), ccntr, rcntr endif else begin find_max, 4, 0, array, c, r, xx, sqrt(2.0), ccntr, rcntr endelse endcase end ; (c-cindx) = 1 endcase stop return end