Home > matGeom > geom2d > registerICP.m

registerICP

PURPOSE ^

REGISTERICP Fit affine transform by Iterative Closest Point algorithm.

SYNOPSIS ^

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

DESCRIPTION ^

REGISTERICP Fit affine transform by Iterative Closest Point algorithm.

   TRANS = registerICP(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-2 array of point coordinates, not necessarily the same size.
   The result TRANS is a 3-by-3 affine transform.

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

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

   Example
   registerICP

   See also
     transforms2d, fitAffineTransform2d, registerPoints3dAffine

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [trans, points] = registerICP(points, target, varargin)
0002 %REGISTERICP Fit affine transform by Iterative Closest Point algorithm.
0003 %
0004 %   TRANS = registerICP(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-2 array of point coordinates, not necessarily the same size.
0008 %   The result TRANS is a 3-by-3 affine transform.
0009 %
0010 %   TRANS = registerICP(POINTS, TARGET, NITER)
0011 %   Specifies the number of iterations for the algorithm.
0012 %
0013 %   [TRANS, POINTS2] = registerICP(...)
0014 %   Also returns the set of transformed points.
0015 %
0016 %   Example
0017 %   registerICP
0018 %
0019 %   See also
0020 %     transforms2d, fitAffineTransform2d, registerPoints3dAffine
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 nIter = 10;
0031 if ~isempty(varargin)
0032     nIter = varargin{1};
0033 end
0034 
0035 % keep original points to transform them at each
0036 trans = [1 0 0;0 1 0;0 0 1];
0037 
0038 for i = 1:nIter
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 = fitAffineTransform2d(points, corrPoints);
0045 
0046     % apply transform, and update cumulated transform
0047     points = transformPoint(points, trans_i);
0048     trans = trans_i * trans;
0049 end

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