pro meanvar,name,num,imean,ivar,hb,clean=clean,norm=norm,dark=dkim ; ; This procedure computes the mean and variance of a set of 2-byte ; integer images acquired by a CCD camera. It accepts as inputs the ; base file name of the images. It returns two floating-point images, ; containing the mean and the variance of the input images, ; respectively. ; ; If the clean keyword is set, an attempt is made to remove CCD hot ; pixels before adding each image to the sums. ; If the norm keyword is set, each image is converted to 2-byte ; INTEGER form and normalized so that its brightest pixel has a ; value of 10000. ; ; If the dark keyword is set, it is an input dark image to be ; subtracted from each image read from disk (before normalizing, ; if this option is selected). ; ; Modified 20 Oct 1993 by D. P. Steele to find the files that match ; the base name (including path) supplied by the user. ; f=FINDFILE(name,COUNT=num) IF num LE 0 THEN BEGIN MESSAGE,'No files found matching supplied name.' RETURN ENDIF FOR j=0,num-1 DO BEGIN ; get j-th image rdkimg,f(j),hb,ij IF j EQ 0 THEN BEGIN ;set things up the first time around s=SIZE(ij) w=s(1) h=s(2) isum=LONARR(w,h) isumsq=DBLARR(w,h) ENDIF ; remove hot pixels IF KEYWORD_SET(clean) THEN img=clean(ij,2,2,3) ELSE img=ij IF KEYWORD_SET(dkim) THEN img=(img-dkim)>0 IF KEYWORD_SET(norm) THEN BEGIN ; Find the 'center of gravity' of the image, and look for the ; maximum pixel value in that neighbourhood IF j EQ 0 THEN BEGIN cols=REPLICATE(FINDGEN(w),1,h) rows=TRANSPOSE(cols) STOP,'Check out cols and rows arrays!' ENDIF cgcol=TOTAL(cols*img)/(w*h) cgrow=TOTAL(rows*img)/(w*h) IF j lt 5 THEN STOP,'cgcol=',cgcol,'cgrow=',cgrow mk,mask mask(cgcol-32:cgcol+32,cgrow-32:cgrow+32)=1 maxpix=MAX(img*mask,loc) one2two,loc,img,maxcol,maxrow PRINT,j,maxpix,maxcol,maxrow,FORMAT='("Image ",'+ $ 'I3,": max pixel value=",I6," at col ",I3,", row ",I3)' img=FIX(ROUND((10000.*img)/maxpix)) ENDIF ; update sum and sum of squares of images isum=isum+img isumsq=isumsq+LONG(img)^2 ENDFOR n=DOUBLE(num) imean=FIX(ROUND(isum/n)) ivar=((isumsq-n*(isum/n)^2)/(n-1)) IF MIN(ivar) LT 0 THEN MESSAGE,'The variance image has negative elements!' RETURN END