1 | % A matrix (npy,npx) to interpolate |
---|

2 | %XIMA: matrix of non-integer x index values (npY,npX) |
---|

3 | %YIMA: matrix of non-integer y index values (npY,npX), (with the same size as XIMA) |
---|

4 | function A_out=interp2_uvmat(A,XIMA,YIMA) |
---|

5 | npx=size(A,2); |
---|

6 | npy=size(A,1); |
---|

7 | npX=size(XIMA,2); |
---|

8 | npY=size(XIMA,1) |
---|

9 | XIMA=reshape(XIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector |
---|

10 | YIMA=reshape(YIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector |
---|

11 | X_delta=XIMA-floor(XIMA);%distance to the closest integer value |
---|

12 | XIMA=floor(XIMA);%integer x index on the image |
---|

13 | Y_delta=YIMA-floor(YIMA);%distance to the closest integer value |
---|

14 | YIMA=floor(YIMA);%integer x index on the image |
---|

15 | flagin=(XIMA>=1 & XIMA<=npx-1 & YIMA >=1 & YIMA<=npy-1);%flagin=1 inside the original image |
---|

16 | ind_in=find(flagin);%list of indices of XIndex for valid values of image indices (inside the original image) |
---|

17 | ind_out=find(~flagin); |
---|

18 | vec_A=double(reshape(A(:,:,1),1,npx*npy));%reshape the original image as a Matlab image vector |
---|

19 | ICOMB=((XIMA-1)*npy+(npy+1-YIMA));%determine the indices in the image Matlab vector corresponding to XIMA and YIMA |
---|

20 | ICOMB=ICOMB(flagin);%selection of the valid indices |
---|

21 | X_delta=X_delta(ind_in); |
---|

22 | Y_delta=Y_delta(ind_in); |
---|

23 | A_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); |
---|

24 | A_out(ind_out)=zeros(size(ind_out)); |
---|

25 | A_out=reshape(A_out,npY,npX);%interpolated image |
---|