[1139] | 1 | %% Test of spline thin plate functions |
---|
| 2 | |
---|
| 3 | x=2*pi*rand(100,1);%set of random x coordinates from 0 to 2pi |
---|
| 4 | y=2*pi*rand(100,1);%set of random y coordinates |
---|
| 5 | %U=exp(-(x-pi).*(x-pi)-(y-pi).*(y-pi));% gaussian |
---|
| 6 | U=x; |
---|
| 7 | [U_smooth,U_tps]=tps_coeff([x y],U,0);%calculate tps coeff, no smoothing |
---|
| 8 | xI=0:0.1:2*pi;%interpolation grid |
---|
| 9 | yI=0:0.1:2*pi; |
---|
| 10 | [XI,YI]=meshgrid(xI,yI); |
---|
| 11 | [npy,npx]=size(XI); |
---|
| 12 | XI=reshape(XI,[],1); |
---|
| 13 | YI=reshape(YI,[],1); |
---|
| 14 | EM = tps_eval([XI YI],[x y]);%evaluate interpolation on the new grid |
---|
| 15 | U_eval=EM*U_tps; |
---|
| 16 | U_eval=reshape(U_eval,npy,npx); |
---|
| 17 | figure(1) |
---|
| 18 | imagesc(U_eval,[0 6]) |
---|
| 19 | title('U matrix') |
---|
| 20 | colorbar |
---|
| 21 | [DMX,DMY] = tps_eval_dxy([XI YI],[x y]); |
---|
| 22 | DUX_eval=DMX*U_tps; |
---|
| 23 | DUY_eval=DMY*U_tps; |
---|
| 24 | DUX_eval=reshape(DUX_eval,npy,npx); |
---|
| 25 | % plot(yI,U_eval(:,5)) |
---|
| 26 | figure(2) |
---|
| 27 | DUY_eval=reshape(DUY_eval,npy,npx); |
---|
| 28 | imagesc(DUX_eval,[-1 1]) |
---|
| 29 | % plot(xI,DU_eval(:,5)) |
---|
| 30 | figure(3) |
---|
| 31 | imagesc(DUY_eval,[-1 1]) |
---|
| 32 | figure(4) |
---|
| 33 | % plot(x,U_eval(50,:),x,DUX_eval(50,:),x,DUY_eval(50,:)) |
---|
| 34 | size(U_eval(50,:)) |
---|
| 35 | size(xI) |
---|
| 36 | plot(xI,U_eval(50,:),xI,DUX_eval(50,:),xI,DUY_eval(50,:)) |
---|