1 | %'interp2_uvmat': linearly interpolate an image or scalar defined on a |
---|
2 | %regular grid USE Matlab interp2 instead |
---|
3 | %-------------------------------------------------------------------- |
---|
4 | %OUTPUT: |
---|
5 | % A_out: matrix of interpolated values at positions (XIMA,YIMA) |
---|
6 | % |
---|
7 | %INPUT: |
---|
8 | % A matrix (npy,npx) to interpolate |
---|
9 | %XIMA: matrix of non-integer x index values (npY,npX) |
---|
10 | %YIMA: matrix of non-integer y index values (npY,npX), (with the same size as XIMA) |
---|
11 | |
---|
12 | %======================================================================= |
---|
13 | % Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France |
---|
14 | % http://www.legi.grenoble-inp.fr |
---|
15 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
16 | % |
---|
17 | % This file is part of the toolbox UVMAT. |
---|
18 | % |
---|
19 | % UVMAT is free software; you can redistribute it and/or modify |
---|
20 | % it under the terms of the GNU General Public License as published |
---|
21 | % by the Free Software Foundation; either version 2 of the license, |
---|
22 | % or (at your option) any later version. |
---|
23 | % |
---|
24 | % UVMAT is distributed in the hope that it will be useful, |
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
27 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
28 | %======================================================================= |
---|
29 | |
---|
30 | function A_out=interp2_uvmat(A,XIMA,YIMA) |
---|
31 | npx=size(A,2); |
---|
32 | npy=size(A,1); |
---|
33 | npX=size(XIMA,2); |
---|
34 | npY=size(XIMA,1); |
---|
35 | XIMA=reshape(XIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector |
---|
36 | YIMA=reshape(YIMA,1,npX*npY)+0.5;%indices corresponding to XIMA, reshaped in a matlab vector |
---|
37 | X_delta=XIMA-floor(XIMA);%distance to the closest integer value |
---|
38 | XIMA=floor(XIMA);%integer x index on the image |
---|
39 | Y_delta=YIMA-floor(YIMA);%distance to the closest integer value |
---|
40 | YIMA=floor(YIMA);%integer x index on the image |
---|
41 | flagin=(XIMA>=1 & XIMA<=npx-1 & YIMA >=1 & YIMA<=npy-1);%flagin=1 inside the original image |
---|
42 | ind_in=find(flagin);%list of indices of XIndex for valid values of image indices (inside the original image) |
---|
43 | ind_out=find(~flagin); |
---|
44 | vec_A=double(reshape(A(:,:,1),1,npx*npy));%reshape the original image as a Matlab image vector |
---|
45 | ICOMB=((XIMA-1)*npy+(npy+1-YIMA));%determine the indices in the image Matlab vector corresponding to XIMA and YIMA |
---|
46 | ICOMB=ICOMB(flagin);%selection of the valid indices |
---|
47 | X_delta=X_delta(ind_in); |
---|
48 | Y_delta=Y_delta(ind_in); |
---|
49 | 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); |
---|
50 | A_out(ind_out)=zeros(size(ind_out)); |
---|
51 | A_out=reshape(A_out,npY,npX);%interpolated image |
---|