;function epiv,img1,img2,maxdisp,spacing=spacing,stretch=stretch,$ ; nopoly=nopoly,fits=fits,denoise=denoise,morefit=morefit, $ ; window=window ; ;PURPOSE: ; Compares two images to extract the local motion ; from one image to the other. ; Please see: ; http://www.physics.emory.edu/~weeks/idl/piv.html ; ;EXAMPLE: ; result=piccomp6d(data(*,*,0),data(*,*,1),10,sp=4) ; result = [dx, dy, dr, error] ;MODIFICATION HISTORY: ; 06/04:created by Doug Anderson(andersondoug@gmail.com) ; 07/04:modified a tiny bit by Eric Weeks ; 07/04:try some large modifications (ERW) ;METHOD: ; A section of img1 is compared to sections of ; img2 in the same neighborhood to find the ; section of img2 that is most like the section ; of img1. The vector connecting the centroid ; of these two sections is the displacement vector ; of interest. Many of these vectors are determined ; for a single image pair. ;ARGUMENTS: ; img1: n X m array ; img2: n X m array ; maxdisp: limits maximum displacement in one ; dimension. So the real max equals ; sqrt(2) * maxdisp in 2-D ;KEYWORDS: ; spacing: defines the spacing between which the ; displacements are sampled, where the ; default=1 ; stretch: multiplies displacement vectors by a ; scalar equal to stretch ; nopoly: to not use poly_fit for sub-pixel accuracy ; fits: within polyf, determines the area of the ; polynomial fit ; denoise:smooths out any discontinous peaks, ; default sensitivity is 0.4 ; morefit: improve poly_fit by trial and error ; local: search for local minimum for correlation, ; rather than global minimum over entire search window ;-------------------------------------------------- function mollify,image,error ; ;PURPOSE: ; Smooths out discontinuous noise from a 2-D array ;EXAMPLE: ; new_img=mollify(image,.4) ;ARGUMENTS ; image:n X m array ; error:0 < num < inf, where amount of smoothing ; increases as num goes to 0 ;METHOD: ; For a given point, mollify finds the average of the ; surrounding points. If the value at that point is ; more than (error*100)% different from the average ; then it is set to the average. img=float(image) img2=img+abs(min(img))+1 m=abs(min(img))+1 x_s=n_elements(img(*,0)) y_s=n_elements(img(0,*)) ;four corners ave=(total(img(0:1,0:1))-img(0,0))/3.+m ti=img(0,0)+m var=ave/ti > ti/ave if (abs(var-1) lt error ) then img(0,0)=ave-m ave=(total(img(0:1,y_s-2:y_s-1))-img(0,y_s-1))/3.+m ti=img(0,y_s-1)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(0,y_s-1)=ave-m ave=(total(img(x_s-2:x_s-1,0:1))-img(x_s-1,0))/3.+m ti=img(x_s-1,0)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(x_s-1,0)=ave-m ave=(total(img(x_s-2:x_s-1,y_s-2:y_s-1))-img2(x_s-1,y_s-1))/3.+m ti=img(x_s-1,y_s-1)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(x_s-1,y_s-1)=ave-m ;top and bottom borders for i=1,x_s-2 do begin ave=(total(img(i-1:i+1,0:1))-img(i,0))/5.+m ti=img(i,0)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(i,0)=ave-m ave=(total(img(i-1:i+1,y_s-2:y_s-1))-img(i,y_s-1))/5.+m ti=img(i,y_s-1)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(i,y_s-1)=ave-m endfor ;left and right borders for i=1,y_s-2 do begin ave=(total(img(0:1,i-1:i+1))-img(0,i))/5.+m ti=img(0,i)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(0,i)=ave-m ave=(total(img(x_s-2:x_s-1,i-1:i+1))-img(x_s-1,i))/5.+m ti=img(x_s-1,i)+m var=ave/ti > ti/ave if (abs(var-1) lt error) then img(x_s-1,i)=ave-m endfor ;the middle of the image for i=1,x_s-2 do begin for j=1,y_s-2 do begin ave=(total(img(i-1:i+1,j-1:j+1))-img(i,j))/8.+m ti=img(i,j)+m var=ave/ti > ti/ave if (abs(var-1) gt error) then img(i,j)=ave-m endfor endfor return,img end ;------------------------------------------------------------ function lsf2d, image,try1,try2,xxa,yya,accur ; ;PURPOSE: ; Based on an initial 2-D poly_fit, this function ; adjusts the values of the coefficients by trial ; and error. ;EXAMPLE: ; ab=lsf2d(means,a,b,[x0,x1],[y0,y1],2) ;ARGUMENTS: ; image: 2-D array of data ; try1: coefficients in the x-dimension from ; poly_fit ; try2: coefficients in the y-dimension from ; poly_fit ; accur: level of precision for the adjustments, ; an integer x, such that 1<=x