diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m b/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m new file mode 100755 index 0000000..314f140 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m | |||
@@ -0,0 +1,49 @@ | |||
1 | function [F,mask] = m_interp4(z,s,t) | ||
2 | %INTERP4 2-D bilinear data interpolation. | ||
3 | % ZI = INTERP4(Z,XI,YI) assumes X = 1:N and Y = 1:M, where | ||
4 | % [M,N] = SIZE(Z). | ||
5 | % | ||
6 | % Copyright (c) 1984-93 by The MathWorks, Inc. | ||
7 | % Clay M. Thompson 4-26-91, revised 7-3-91, 3-22-93 by CMT. | ||
8 | % | ||
9 | % modified to | ||
10 | |||
11 | |||
12 | [nrows,ncols] = size(z); | ||
13 | |||
14 | |||
15 | if any(size(z)<[3 3]), error('Z must be at least 3-by-3.'); end | ||
16 | if size(s)~=size(t), error('XI and YI must be the same size.'); end | ||
17 | |||
18 | % Check for out of range values of s and set to 1 | ||
19 | sout = find((s<1)|(s>ncols)); | ||
20 | if length(sout)>0, s(sout) = ones(size(sout)); end | ||
21 | |||
22 | % Check for out of range values of t and set to 1 | ||
23 | tout = find((t<1)|(t>nrows)); | ||
24 | if length(tout)>0, t(tout) = ones(size(tout)); end | ||
25 | |||
26 | % Matrix element indexing | ||
27 | ndx = floor(t)+floor(s-1)*nrows; | ||
28 | |||
29 | % Compute intepolation parameters, check for boundary value. | ||
30 | d = find(s==ncols); | ||
31 | s(:) = (s - floor(s)); | ||
32 | if length(d)>0, s(d) = s(d)+1; ndx(d) = ndx(d)-nrows; end | ||
33 | |||
34 | % Compute intepolation parameters, check for boundary value. | ||
35 | d = find(t==nrows); | ||
36 | t(:) = (t - floor(t)); | ||
37 | if length(d)>0, t(d) = t(d)+1; ndx(d) = ndx(d)-1; end | ||
38 | d = []; | ||
39 | |||
40 | % Now interpolate, reuse u and v to save memory. | ||
41 | F = ( z(ndx).*(1-t) + z(ndx+1).*t ).*(1-s) + ... | ||
42 | ( z(ndx+nrows).*(1-t) + z(ndx+(nrows+1)).*t ).*s; | ||
43 | |||
44 | mask = ones(size(z)); | ||
45 | |||
46 | % Now set out of range values to zeros. | ||
47 | if length(sout)>0, F(sout) = zeros(size(sout));mask(sout)=zeros(size(sout));end | ||
48 | if length(tout)>0, F(tout) = zeros(size(tout));mask(tout)=zeros(size(tout));end | ||
49 | |||