source: trunk/src/tps_eval.m @ 1156

Last change on this file since 1156 was 1127, checked in by g7moreau, 11 months ago

Update Joel email

File size: 2.4 KB
Line 
1%'tps_eval': calculate the thin plate spline (tps) interpolation at a set of points
2% see tps_coeff.m for more information and test_tps.m for an example
3%------------------------------------------------------------------------
4% function EM = tps_eval(dsites,ctrs)
5%------------------------------------------------------------------------
6% OUTPUT:
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%  use : U_interp=EM*U_tps
11%
12% INPUT:
13%  dsites:  Mxs matrix representing the postions of the M 'observation' sites, with s the space dimension
14%  ctrs: Nxs matrix  representing the postions of the N centers, sources of the tps,
15%
16% RELATED FUNCTIONS:
17%  tps_coeff, tps_eval_dxy
18%  tps_coeff_field, set_subdomains, filter_tps, calc_field
19
20%=======================================================================
21% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
22%   http://www.legi.grenoble-inp.fr
23%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
24%
25%     This file is part of the toolbox UVMAT.
26%
27%     UVMAT is free software; you can redistribute it and/or modify
28%     it under the terms of the GNU General Public License as published
29%     by the Free Software Foundation; either version 2 of the license,
30%     or (at your option) any later version.
31%
32%     UVMAT is distributed in the hope that it will be useful,
33%     but WITHOUT ANY WARRANTY; without even the implied warranty of
34%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35%     GNU General Public License (see LICENSE.txt) for more details.
36%=======================================================================
37
38function EM = tps_eval(dsites,ctrs)
39[M,s] = size(dsites); [N,s] = size(ctrs);
40EM = zeros(M,N);
41
42% calculate distance matrix: accumulate sum of squares of coordinate differences
43% The ndgrid command produces two MxN matrices:
44%   Dsite, consisting of N identical columns (each containing
45%       the d-th coordinate of the M data sites)
46%   Ctrs, consisting of M identical rows (each containing
47%       the d-th coordinate of the N centers)
48for d=1:s
49 [Dsites,Ctrs] = ndgrid(dsites(:,d),ctrs(:,d));
50 EM = EM + (Dsites-Ctrs).^2;%EM=square of distance matrices
51end
52
53% calculate tps
54np=find(EM~=0);
55EM(np) = EM(np).*log(EM(np))/2;%= tps formula r^2 log(r) (EM=r^2)
56
57% add linear gradient part:
58EM = [EM ones(M,1) dsites];
Note: See TracBrowser for help on using the repository browser.