PRO meancent,img,c,r,tm,debug=debug,radius=rad,notv=notv ; Decide whether to display images dispim=NOT KEYWORD_SET(notv) ; save !ORDER oldorder=!ORDER !ORDER=0 ; work with 256x256 images s=SIZE(img) IF s(1) NE 256 THEN tmp=REBIN(img,256,256) ELSE tmp=img ; display the image IF dispim THEN TVSCL,tmp ; select pixels viewing LBS ;maxpix=MAX(tmp) maxpix=pcentile(tmp,0.999) sf=0.25 mk,omask ; original mask omask(WHERE(tmp GT sf*maxpix))=1 ; remove outlying pixels by opening the mask cross=[[0,1,0],[1,1,1],[0,1,0]] mask=DILATE(omask,cross) ; altered mask box=REPLICATE(1,3,3) mask=ERODE(mask,box) mask=ERODE(mask,box) ; generate column and row arrays x=BYTE(INDGEN(256)#REPLICATE(1,1,256)) y=TRANSPOSE(x) ; form sums for calculating mean column and mean row tmx=TOTAL(mask*x) ; altered mask tmy=TOTAL(mask*y) tm=TOTAL(mask) IF KEYWORD_SET(debug) THEN PRINT,tmx,tmy,tm IF tm GE 10 THEN BEGIN ; image actually shows an extended bright object c=tmx/tm r=tmy/tm ; set outlying bright pixels to zero cols=omask*x ; original mask rows=omask*y outliers=WHERE(SQRT((cols-c)^2+(rows-r)^2) GT 50) tmp(cols(outliers),rows(outliers))=0 IF dispim THEN TVSCL,tmp,2 ; estimate radius of LBS image using edge of LBS image stmp=SOBEL(tmp) edge=WHERE(stmp GT MAX(stmp)/2.) one2two,edge,stmp,ce,re ; calculate mean distance from center to edge rad=mean(SQRT((ce-c)^2+(re-r)^2)) IF dispim THEN arcs,rad,0,360,c,r,/dev ENDIF ELSE BEGIN MESSAGE,'"Bright feature" contains <10 pixels! Returned center meaningless',/INFORMATIONAL c=-999 r=-999 rad=-999 ENDELSE ; restore !ORDER !ORDER=oldorder RETURN END