Home > matGeom > geom3d > registerPoints3dAffine.m

registerPoints3dAffine

PURPOSE ^

Fit 3D affine transform using iterative algorithm.

SYNOPSIS ^

function [trans, points] = registerPoints3dAffine(points, target, varargin)

DESCRIPTION ^

 Fit 3D affine transform using iterative algorithm.

   TRANS = registerPoints3dAffine(POINTS, TARGET)
   Computes the affine transform that maps the shape defines by POINTS
   onto the shape defined by the points TARGET. Both POINTS and TARGET are
   N-by-3 array of point coordinates, not necessarily the same size.
   The result TRANS is a 4-by-4 affine transform.

   TRANS = registerPoints3dAffine(POINTS, TARGET, NITER)
   Specifies the number of iterations for the algorithm.

   [TRANS, POINTS2] = registerPoints3dAffine(...)
   Also returns the set of transformed points.

   Example
     registerPoints3dAffine

   See also
     transforms3d, fitAffineTransform3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [trans, points] = registerPoints3dAffine(points, target, varargin)
0002 % Fit 3D affine transform using iterative algorithm.
0003 %
0004 %   TRANS = registerPoints3dAffine(POINTS, TARGET)
0005 %   Computes the affine transform that maps the shape defines by POINTS
0006 %   onto the shape defined by the points TARGET. Both POINTS and TARGET are
0007 %   N-by-3 array of point coordinates, not necessarily the same size.
0008 %   The result TRANS is a 4-by-4 affine transform.
0009 %
0010 %   TRANS = registerPoints3dAffine(POINTS, TARGET, NITER)
0011 %   Specifies the number of iterations for the algorithm.
0012 %
0013 %   [TRANS, POINTS2] = registerPoints3dAffine(...)
0014 %   Also returns the set of transformed points.
0015 %
0016 %   Example
0017 %     registerPoints3dAffine
0018 %
0019 %   See also
0020 %     transforms3d, fitAffineTransform3d
0021 %
0022  
0023 % ------
0024 % Author: David Legland
0025 % e-mail: david.legland@inra.fr
0026 % Created: 2015-02-24,    using Matlab 8.4.0.150421 (R2014b)
0027 % Copyright 2015 INRA - Cepia Software Platform.
0028 
0029 
0030 nIters = 10;
0031 if ~isempty(varargin)
0032     nIters = varargin{1};
0033 end
0034 
0035 % keep original points to transform them at each
0036 trans = [1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1];
0037 
0038 for i = 1:nIters
0039     % identify target points for each source point
0040     inds = findClosestPoint(points, target);
0041     corrPoints = target(inds, :);
0042     
0043     % compute transform for current iteration
0044     trans_i = fitAffineTransform3d(points, corrPoints);
0045 
0046     % apply transform, and update cumulated transform
0047     points = transformPoint3d(points, trans_i);
0048     trans = trans_i * trans;
0049 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019