3d-deformation-algorithms's People
3d-deformation-algorithms's Issues
TPS3D improvement ideas
Hello! I saw your numpy version of Yang Yang's matlab 3D Thin Plate Spline Warping Function and thought you might care to incorporate some of my improvements (clearer (I think), tidier, and more efficient). I saw that you replicated it very true to the source though I did catch many improvements you made yourself! Feel free to close this if you don't care to! If not, then potentially my matlab version may help someone on the internet :P
Specifically I would use least squares inverse rather than explicitly finding the pseudo-inverse of L; I would use norms instead of his written out versions; and I would drop his g terms
Cheers!!
Single file (dual file version below)
%======================================================
% 3D Thin Plate Spline by Yang Yang (05.05.2012)
% Yang Yang (2021). 3D Thin Plate Spline Warping Function
% (https://www.mathworks.com/matlabcentral/fileexchange/37576-3d-thin-plate-spline-warping-function),
% MATLAB Central File Exchange. Retrieved December 27, 2021.
%
% Adapted by Sanders Aspelund (27.12.2021)
%======================================================
function [transformedPoints] = TPS3D(measuredPoints,truthPoints,toBeTransformedPoints)
%======================================================
% Calculate Parameters
%======================================================
npnts = size(measuredPoints,1);
%calculate kernel function R
K = zeros(npnts, npnts);
for rr = 1:npnts
for cc = rr:npnts
K(rr,cc) = norm( (measuredPoints(rr,:) - measuredPoints(cc,:)) ); %R^2
K(cc,rr) = K(rr,cc);
end
end
K = max(K,1e-320);
% Calculate P matrix
P = [ones(npnts,1), measuredPoints]; %nX4 for 3D
% Calculate L matrix
L = [K, P;
P', zeros(4,4)]; %zeros(4,4) for 3D
% Calculate weights
param = L\[truthPoints; zeros(4,3)]; %zeros(4,3) for 3D
%======================================================
% Calculate new coordinates (x',y',z') for each points
%======================================================
pntsNum=size(toBeTransformedPoints,1);
% Calculate kernel function
K2 = zeros(pntsNum, npnts);
for nn = 1:npnts
K2(:,nn) = vecnorm( toBeTransformedPoints-measuredPoints(nn,:) ,2,2);
end
K2 = max(K2,1e-320);
P2 = [ones(pntsNum,1), toBeTransformedPoints];
L2 = [K2, P2];
transformedPoints = L2 * param;
Two files if params isn't ever changing
%======================================================
% 3D Thin Plate Spline by Yang Yang (05.05.2012)
% Yang Yang (2021). 3D Thin Plate Spline Warping Function
% (https://www.mathworks.com/matlabcentral/fileexchange/37576-3d-thin-plate-spline-warping-function),
% MATLAB Central File Exchange. Retrieved December 27, 2021.
%
% Adapted by Sanders Aspelund (27.12.2021)
%======================================================
function [param] = TPS3D_param(measuredPoints, truthPoints)
%======================================================
% Calculate Parameters
%======================================================
npnts = size(measuredPoints,1);
%calculate kernel function R
K = zeros(npnts, npnts);
for rr = 1:npnts
for cc = rr:npnts
K(rr,cc) = norm( (measuredPoints(rr,:) - measuredPoints(cc,:)) ); %R^2
K(cc,rr) = K(rr,cc);
end
end
K = max(K,1e-320);
% Calculate P matrix
P = [ones(npnts,1), measuredPoints]; %nX4 for 3D
% Calculate L matrix
L = [K, P;
P', zeros(4,4)]; %zeros(4,4) for 3D
% Calculate weights
param = L\[truthPoints; zeros(4,3)]; %zeros(4,3) for 3D
%======================================================
% 3D Thin Plate Spline by Yang Yang (05.05.2012)
% Yang Yang (2021). 3D Thin Plate Spline Warping Function
% (https://www.mathworks.com/matlabcentral/fileexchange/37576-3d-thin-plate-spline-warping-function),
% MATLAB Central File Exchange. Retrieved December 27, 2021.
%
% Adapted by Sanders Aspelund (27.12.2021)
%======================================================
function [transformedPoints] = TPS3D_transformPts(originallyMeasuredPoints,toBeTransformedPoints,param)
%======================================================
% Calculate new coordinates (x',y',z') for each points
%======================================================
npnts = size(originallyMeasuredPoints,1);
pntsNum=size(toBeTransformedPoints,1);
% Calculate kernel function
K2 = zeros(pntsNum, npnts);
for nn = 1:npnts
K2(:,nn) = vecnorm( toBeTransformedPoints-originallyMeasuredPoints(nn,:) ,2,2);
end
K2 = max(K2,1e-320);
P2 = [ones(pntsNum,1), toBeTransformedPoints];
L2 = [K2, P2];
transformedPoints = L2 * param;
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.