source: trunk/src/interp2_uvmat.m @ 646

Last change on this file since 646 was 646, checked in by sommeria, 11 years ago

various update, bugs to be expected

File size: 1.7 KB
Line 
1%'interp2_uvmat': linearly interpolate an image or scalar defined on a regular grid
2%--------------------------------------------------------------------
3%OUTPUT:
4% A_out: matrix of interpolated values at positions (XIMA,YIMA)
5%
6%INPUT:
7% A matrix (npy,npx) to interpolate
8%XIMA: matrix of non-integer x index values (npY,npX)
9%YIMA: matrix of non-integer y index values (npY,npX), (with the same size as XIMA)
10
11function A_out=interp2_uvmat(A,XIMA,YIMA)
12npx=size(A,2);
13npy=size(A,1);
14npX=size(XIMA,2);
15npY=size(XIMA,1);
16XIMA=reshape(XIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector
17YIMA=reshape(YIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector
18X_delta=XIMA-floor(XIMA);%distance to the closest integer value
19XIMA=floor(XIMA);%integer x index on the image
20Y_delta=YIMA-floor(YIMA);%distance to the closest integer value
21YIMA=floor(YIMA);%integer x index on the image       
22flagin=(XIMA>=1 & XIMA<=npx-1 & YIMA >=1 & YIMA<=npy-1);%flagin=1 inside the original image
23ind_in=find(flagin);%list of indices of XIndex for valid values of image indices (inside the original image)
24ind_out=find(~flagin);     
25vec_A=double(reshape(A(:,:,1),1,npx*npy));%reshape the original image as a Matlab image vector
26ICOMB=((XIMA-1)*npy+(npy+1-YIMA));%determine the indices in the image Matlab vector corresponding to XIMA and YIMA
27ICOMB=ICOMB(flagin);%selection of the valid indices
28X_delta=X_delta(ind_in);
29Y_delta=Y_delta(ind_in);
30A_out(ind_in)=(1-Y_delta).*(1-X_delta).*vec_A(ICOMB)+Y_delta.*(1-X_delta).*vec_A(ICOMB-1)+X_delta.*(1-Y_delta).*vec_A(ICOMB+npy)+X_delta.*Y_delta.*vec_A(ICOMB+npy-1);
31A_out(ind_out)=zeros(size(ind_out));
32A_out=reshape(A_out,npY,npX);%interpolated image
Note: See TracBrowser for help on using the repository browser.