function center2,i,x,y,l ;+ ; NAME: ; center2 ; PURPOSE: ; Centroiding routine. ; By integrating over the pixel values of a set area, this function returns ; the coordinates of the center of the object. This function is called by ; the procedures I_DIS and I_CENTER in the procedure I_BROWSE. ; CATEGORY: ; Image analysis. ; CALLING SEQUENCE: ; c=center2(i,x,y) ; ;returns the center coordinates, c, from a 26 pixel square ; ;with x,y as the center of the square and i as the image ; ;being used ; c=center2(i,x,y,l) ; ;same as above except it uses a square of size l pixels ; ;rather than 26 pixels ; INPUTS: ; i: the image array being used ; x: the x coordinate of the center of the square to centroid on ; y: the y coordinate of the center of the square to centroid on ; OPTIONAL INPUT PARAMETERS: ; l: the size of the square to centroid on ; KEYWORDS: ; OUTPUTS: ; Prints the resulting center coordinates, and returns them as the vector c ; OPTIONAL OUTPUT PARAMETERS: ; NONE ; COMMON BLOCKS: ; NONE: ; SIDE EFFECTS: ; NONE ; RESTRICTIONS: ; NONE ; PROCEDURE: ; enter i,x,and y and it returns the centroiding results ; MODIFICATION HISTORY: ; NLC - 03/25/95 created ;- ; CHECKS TO SEE IF l WAS ENTERED OR NOT if n_params(0) EQ 3 then l=26 ; DEFINE THE SQUARE TO USE ORIGINALLY xs=round(x-l/2) ys=round(y-l/2) ; THE CENTROID IS DETERMINED ITERATIVELY BY EACH TIME MAKING THE SQUARE SLIGHTLY ;SMALLER - IT DOES THIS FOUR TIMES for z=1,4 do begin ;MAKING A SUBIMAGE OF THE SQUARE AREA TO CENTROID ON for j=ys,ys+l do begin for k=xs,xs+l do begin if k EQ xs then si=i(k,j) else si=[si,i(k,j)] endfor if j EQ ys then sit=si else sit=[[sit],[si]] endfor ; SETTING VALUES THAT ARE BELOW THE NOISE LEVEL TO ZERO maxi=max(sit) cut=sqrt(maxi/30) for p=0,l do begin for q=0,l do begin if sit(q,p) LT cut then sit(q,p)=0 endfor endfor ; CREATING TWO ARRAYS THAT CONTAIN THE PIXEL VALUES WEIGHTED CORRECTLY BY THEIR ; X AND Y DISTANCES FROM THE TOP LEFT CORNER b=0 for n=0,l do begin a=0 for m=0,l do begin if m EQ 0 then mx=a*sit(m,n) else mx=[mx,a*sit(m,n)] if m EQ 0 then my=b*sit(m,n) else my=[my,b*sit(m,n)] a=a+1 endfor if n EQ 0 then mxt=mx else mxt=[[mxt],[mx]] if n EQ 0 then myt=my else myt=[[myt],[my]] b=b+1 endfor ; TOTALING THE UNWEIGHTED PIXEL VALUES, AND THE WIEGTHED X AND Y ARRAYS t=total(sit) tx=total(mxt) ty=total(myt) ; COMPUTING THE COORDINATES OF THE CENTER xc=tx/t+xs yc=ty/t+ys ; LOOPING IF NECESSARY if z EQ 1 then l=l-4 if z EQ 2 then l=l-2 if z EQ 3 then l=l-2 ; USING A NEW SQUARE SIZE IF STILL LOOPING xs=round(xc-l/2) ys=round(yc-l/2) endfor ; DISPLAYING AND RETURNING THE RESULT print,'Center:',[xc,yc] return, [xc,yc] end