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@inrae.fr
0026 % Created: 2015-02-24, using Matlab 8.4.0.150421 (R2014b)
0027 % Copyright 2015-2024 INRA - Cepia Software Platform
0028 
0029 nIter = 10;
0030 if ~isempty(varargin)
0031     nIter = varargin{1};
0032 end
0033 
0034 % keep original points to transform them at each
0035 trans = [1 0 0;0 1 0;0 0 1];
0036 
0037 for i = 1:nIter
0038     % identify target points for each source point
0039     inds = findClosestPoint(points, target);
0040     corrPoints = target(inds, :);
0041     
0042     % compute transform for current iteration
0043     trans_i = fitAffineTransform2d(points, corrPoints);
0044 
0045     % apply transform, and update cumulated transform
0046     points = transformPoint(points, trans_i);
0047     trans = trans_i * trans;
0048 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022