1 | %'tps_eval': calculate the thin plate spline (tps) interpolation at a set of points |
---|
2 | % see tps_ceff for more information |
---|
3 | %------------------------------------------------------------------------ |
---|
4 | % function EM = tps_eval(dsites,ctrs) |
---|
5 | %------------------------------------------------------------------------ |
---|
6 | % OUPUT: |
---|
7 | % EM: Mx(N+s) matrix representing the contributions at the M sites |
---|
8 | % from unit sources located at each of the N centers, + (s+1) columns |
---|
9 | % representing the contribution of the linear gradient part. |
---|
10 | % |
---|
11 | %INPUT: |
---|
12 | %dsites: Nxs matrix representing the postions of the N 'observation' sites, with s the space dimension |
---|
13 | %ctrs: Mxs matrix representing the postions of the M centers, sources of the tps, |
---|
14 | % |
---|
15 | % related functions: |
---|
16 | % tps_coeff, tps_eval_dxy |
---|
17 | |
---|
18 | function EM = tps_eval(dsites,ctrs) |
---|
19 | [M,s] = size(dsites); [N,s] = size(ctrs); |
---|
20 | EM = zeros(M,N); |
---|
21 | |
---|
22 | % calculate distance matrix: accumulate sum of squares of coordinate differences |
---|
23 | % The ndgrid command produces two MxN matrices: |
---|
24 | % Dsite, consisting of N identical columns (each containing |
---|
25 | % the d-th coordinate of the M data sites) |
---|
26 | % Ctrs, consisting of M identical rows (each containing |
---|
27 | % the d-th coordinate of the N centers) |
---|
28 | for d=1:s |
---|
29 | [Dsites,Ctrs] = ndgrid(dsites(:,d),ctrs(:,d)); |
---|
30 | EM = EM + (Dsites-Ctrs).^2;%EM=square of distance matrices |
---|
31 | end |
---|
32 | |
---|
33 | % calculate tps |
---|
34 | np=find(EM~=0); |
---|
35 | EM(np) = EM(np).*log(EM(np))/2;%= tps formula r^2 log(r) (EM=r^2) |
---|
36 | |
---|
37 | % add linear gradient part: |
---|
38 | EM = [EM ones(M,1) dsites]; |
---|