[356] | 1 | %'tps_eval_dxy': calculate the derivatives of thin plate spline (tps) interpolation at a set of points (limited to the 2D case) |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function [DMX,DMY] = tps_eval_dxy(dsites,ctrs) |
---|
| 4 | %------------------------------------------------------------------------ |
---|
| 5 | % OUTPUT: |
---|
| 6 | % DMX: Mx(N+3) matrix representing the contributions to the X |
---|
| 7 | % derivatives at the M sites from unit sources located at each of the N |
---|
| 8 | % centers, + 3 columns representing the contribution of the linear gradient part. |
---|
| 9 | % DMY: idem for Y derivatives |
---|
[246] | 10 | % |
---|
| 11 | % INPUT: |
---|
[356] | 12 | % dsites: M x s matrix of interpolation site coordinates (s=space dimension=2 here) |
---|
[246] | 13 | % ctrs: N x s matrix of centre coordinates (initial data) |
---|
| 14 | % |
---|
[356] | 15 | % related functions: |
---|
| 16 | % tps_coeff, tps_eval |
---|
| 17 | |
---|
[247] | 18 | function [DMX,DMY] = tps_eval_dxy(dsites,ctrs) |
---|
[246] | 19 | %% matrix declarations |
---|
| 20 | [M,s] = size(dsites); [N,s] = size(ctrs); |
---|
[247] | 21 | Dsites=zeros(M,N); |
---|
[246] | 22 | DM = zeros(M,N); |
---|
[247] | 23 | % DMXY = zeros(M,N+1+s); |
---|
[246] | 24 | |
---|
| 25 | %% Accumulate sum of squares of coordinate differences |
---|
| 26 | % The ndgrid command produces two MxN matrices: |
---|
| 27 | % Dsites, consisting of N identical columns (each containing |
---|
| 28 | % the d-th coordinate of the M interpolation sites) |
---|
| 29 | % Ctrs, consisting of M identical rows (each containing |
---|
| 30 | % the d-th coordinate of the N centers) |
---|
| 31 | |
---|
[247] | 32 | [Dsites,Ctrs] = ndgrid(dsites(:,1),ctrs(:,1));%d coordinates of interpolation points (Dsites) and initial points (Ctrs) |
---|
[434] | 33 | DX=Dsites-Ctrs;% set of x wise distances between sites and centres |
---|
[247] | 34 | [Dsites,Ctrs] = ndgrid(dsites(:,2),ctrs(:,2));%d coordinates of interpolation points (Dsites) and initial points (Ctrs) |
---|
[434] | 35 | DY=Dsites-Ctrs;% set of y wise distances between sites and centres |
---|
[247] | 36 | DM = DX.*DX + DY.*DY;% add d component squared |
---|
| 37 | |
---|
| 38 | %% calculate matrix of tps derivatives |
---|
| 39 | DM(DM~=0) = log(DM(DM~=0))+1; %=2 log(r)+1 derivative of the tps r^2 log(r) |
---|
| 40 | |
---|
| 41 | DMX=[DX.*DM zeros(M,1) ones(M,1) zeros(M,1)];% effect of mean gradient |
---|
[434] | 42 | DMY=[DY.*DM zeros(M,1) zeros(M,1) ones(M,1)];% effect of mean gradient |
---|
[247] | 43 | |
---|