The SLAMICP library is a Free and Open Source library that performs Iterative Closest Point matching focused on mobile robot self-localization and map creation using LIDAR data.
The Iterative Closest Point (ICP) is a matching technique used to determine the transformation matrix that minimizes the distance between point clouds.
Example calls to the SLAMICP library using a MATLAB wrapper ( includded in the library as a precompiled MEX file for Windows®):
>> [ Pi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, N, Outlierthreshold );
The parameters used in the calls are:
M, is the point cloud defining the map of the environment.
Ti, is the point cloud defining the i'th LIDAR scan that will be matched with the map M.
Mi, is the map updated with the information included in the scan Ti
Mi-1, is the map before incorporating the new information included in the scan Ti
inlierthreshold, is the threshold distance applied to the matched points to classify a point as an inlier (used by the ICP matching), default = 0.3 units
method, the valid ICP methods are: 'point_to_point' or 'point_to_plane' (faster if the normals N are provided)
maxiter, is the maximum number of iterations allowed during the ICP matching
P, is the current position and orientation of the mobile robot in the map M expressed as: P = ( x, y, θ )
Pi, is the current position of the mobile robot in the map M expressed as: Pi = ( xi, yi, θi )
Pi-1, is the initial guess of Pi, it describes the previous position and orientation of the mobile robot updated with the information of the encoders (if available)
N, are the normals of the map M (use N = [] if the normals are unknown or not used)
Ni, are the normals of the map Mi
Ni-1, are the normals of the map Mi-1 (use Ni-1 = [] if the normals are unknown or not used)
Outlierthreshold, is the threshold distance applied to the matched points to classify a point of tTi as an outlier (does not affect the ICP matching), default = 0.3 units
niter, is the number of iterations performed during ICP matching
md, is the mean inlier distance (computed from the distance between the matched (inlier) points)
Oindex, are the index of the points of Ti classified as outliers
Ocoords, are the coordinates of the outliers expressed in the coordinates of M (transformed outliers)
tTi, is the current (i'th) LIDAR scan (Ti) expressed in the coordinates of M (transformed LIDAR scan)
Representation of example input ( Mi-1, Ti ) and output ( tTi, Mi ) 2D point clouds:
Based on the LIBICP library
The SLAMICP library is based on LIBICP (LIBrary for Iterative Closest Point fitting) which is a cross-platfrom C++ library with MATLAB wrappers for fitting 2d or 3d point clouds with respect to each other. Currently it implements the SVD-based point-to-point algorithm as well as the linearized point-to-plane algorithm. It also supports outlier rejection and is accelerated by the use of k-d trees as well as a coarse matching stage using only a subset of all points.
Compared with LIBICP, the SLAMICP library returns the number of iterations, the mean inlier distance, the outliers, the transformed point cloud and the updated map.
The SLAMICP function computes the transformation (Pi) that aligns the input point cloud (Ti) with a reference point cloud (M).
This version is faster when using the method 'point_to_plane' when the normals (N) are precomputed.
A MATLAB wrapper is provided as precompiled MEX file for Windows®.
Example MATLAB calls for method = 'point_to_plane'
% Precomputation of the normals N of a (already built) map M >>N = SLAMICP(M);
% Call to match Ti with Mi-1 and update the map Mi and the normals Ni, faster, ideal for Simultaneous Localization And Mapping (SLAM)
>> [ Pi, niter, md, Oindx, Ocoords, tTi, Mi, Ni ] = SLAMICP( Mi-1, Ti, inlierthreshold, method, maxiter, Pi-1, Ni-1, Outlierthreshold );
% Call to match Ti with Mi-1 and update the map Mi (slowest, the normals are computed on each call)
>> [ Pi, niter, md, Oindx, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, inlierthreshold, method, maxiter, Pi-1, [], Outlierthreshold );
% Call to match Ti with M without updating the map (faster), ideal for self-localization
>> [ Pi, niter, md, Oindx, Ocoords, tTi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, N, Outlierthreshold );
% Call to match Ti with M without updating the map (slower, the normals are computed on each call)
>> [ Pi, niter, md, Oindx, Ocoords, tTi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, [], Outlierthreshold );
>>Pi = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, N); % fastest, ideal for mobile robot self-localization using a map M and its normals N, Pi = ( xi, yi, θi ) >>Pi = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, []); % performing mobile robot self-localization, Pi = ( xi, yi, θi )
% Display the help and usage instructions
>> SLAMICP( );
% Obtain the outliers of tTi (transformed Ti according to Pi ), matching and merging only the outliers of tTi (listed in Ocoords ) with Mi-1 (no ICP iterations) to create Mi >> [ ~, ~, ~, Oindex, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, inlierthreshold, method, 0, Pi, Outlierthreshold );
% Obtain the outliers of tTi (transformed Ti according to Pi )
>> [ ~, ~, ~, Oindex, Ocoords, tTi ] = SLAMICP( M, Ti, inlierthreshold, method, 0, Pi, Outlierthreshold );
% Obtain tTi (transformed Ti according to Pi ) and merge all points of tTi (all are outliers because Outlierthreshold = 0 ) with Mi-1 (no ICP iterations) to create Mi >> [ ~, ~, ~, Oindex, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, 0, method, 0, Pi, 0 );
% Obtain tTi (transformed Ti using Pi )
>> [ ~, ~, ~, ~, ~, tTi ] = SLAMICP( M, Ti, 0, method, 0, Pi );
Download SLAMICP V5.3 (newest version)
06-02-2026: SLAMICP_V53.rar - Includes a precompiled MEX file for MATLAB under Windows®
21-12-2023: SLAMICP_V51.rar - Includes a precompiled MEX file for MATLAB under Windows®
This example loads some raw scans gathered from a UTM-30LX 2D LiDAR during a small displacement, match the scans, and creates a 2D Map of the visited area.
% Load example data
load scans_2D iteration
% Get number of scans
numIterations = length(iteration);
% Initialize SLAMICP parameters
inlierTh = 0.3; % Scalar. Max distance to consider a point an inlier (-1 = all)
initialPos = [0,0,0]; % Initial position guess vector. [x, y, yaw]
method = 'point_to_plane'; % String. Matching strategy String 'point_to_point' or 'point_to_plane'
maxIter = 20; % Scalar. Maximum number of iterations
Normals = []; % Normals of M. Use [] if unknown
outlierTh = 0.1; % Threshold for detecting outliers of M in output
% Initialize M
M = iteration{1}.scan;
% Initialize plots
figure();
map1Ax = axes;
% Initialize empty objects
mapObj = [];
% Main loop
for itID = 2:1:numIterations
% Get a new scan
T = iteration{itID}.scan;
% Run SLAMPIC
[initialPos, ~, ~, ~, outliersIndx, ~, M, Normals] = SLAMICP(M, T, inlierTh, method, maxIter, initialPos, Normals, outlierTh);
% Update map
mapObj = updateMap(map1Ax, mapObj, M, outliersIndx);
% Process GUI callbacks
drawnow;
% Show progress
disp(['Iteration ',num2str(itID),'/',num2str(numIterations)]);
end
function mapObj = updateMap(mainAx, mapObj, points, ol)
if isempty(mapObj)
mapObj.map = plot(mainAx, points(:,1), points(:,2),'b.');
hold(mainAx,'on');
if isempty(ol)
mapObj.ol = plot(mainAx, nan, nan,'r.');
else
mapObj.ol = plot(mainAx, ol(:,1), ol(:,2),'r.', 'MarkerSize',30);
end
This example loads some raw scans gathered from a Mid-360 3D LiDAR during a small displacement, match the scans, and creates a 3D Map of the room.
% Load example scans
load scanData.mat scanData
% Get the number of scans in the dataset
numScans = length(scanData);
% Initialize SLAMICP parameters
inlierTh = 3000; % Scalar. Max distance to consider a point an inlier (-1 = all)
method = 'point_to_plane'; % String. Matching strategy String 'point_to_point' or 'point_to_plane'
maxIter = 3; % Scalar. Maximum number of iterations
initialPos = zeros(1, 6); % Initial position guess vector. [x, y, z, Yaw, Pitch, Roll]
% Rotation Order: Z(Yaw) -> Y(Pitch) -> X(Roll)
Normals = []; % Normals of M. Use [] if unknown
outlierTh = 30; % Threshold for detecting outliers of M in output
% Use the first scan as initial Map
M = scanData{1}.scan;
% Main process loop
for scanID = 2:numScans
% Load the next scan as Template
T = scanData{scanID}.scan;
% Run ICP to calculate the new position of the LIDAR on the Map, ep
[initialPos, ~, ~, ~, ~, ~, M, Normals] = SLAMICP(M, T, inlierTh, method, maxIter, initialPos, Normals, outlierTh);
% initialPos = [x, y, z, Yaw, Pitch, Roll]. Updated position of the
% robot, which is the initialPos of the robot for the next
% iteration.
% M = NxnDims matrix. Updated Map (Model + incorporated outliers).
% Normals = NxnDims matrix. Updated Normals from all points of M.
disp(['Building map... (scan ', num2str(scanID),'/',num2str(numScans),')']);
end
% Create a figure and axis to display the result
figure;
pc = pointCloud(M);
pcshow(pc);
Download all files required to run the 3D Map application example
03-02-2026: example1.rar (the map is updated at the end of the matching)
The PCMerge function applies a transformation to the current LIDAR scan (Ti) and merges the result with the reference point cloud (Mi-1).
A MATLAB wrapper is provided as precompiled MEX file for Windows®.
Example MATLAB calls
% Create an updated map Mi : 1) transform Ti using Pi = ( xi, yi, θi ) obtained with SLAMICP and 2) merge the result with the original map Mi-1 >> [ Mi, tTi ] = PCMerge( Mi-1, Ti, Pi ); >>Mi = PCMerge( Mi-1, Ti, Pi );
% Create an updated map Mi : 1) transform Ti using Trfit = ( R( θ ), t ) obtained with LIBICP and 2) merge the result with the original map Mi-1 >> [ Mi, tTi ] = PCMerge( Mi-1, Ti, Trfit ); >>Mi = PCMerge( Mi-1, Ti, Trfit );
The ComputeNormals function computes the normals of a point cloud.
A MATLAB wrapper is provided as precompiled MEX file for Windows®.
Example MATLAB call
% Optimized computation of the normals N (red arrows) of a map M (blue dots)
>>N = ComputeNormals(M, Neighbours); >>N = ComputeNormals(M); % Neighbours = 10 by default
The SLAMICP function computes the transformation (Pi) that aligns the input point cloud (Ti) with a reference point cloud (M).
A MATLAB wrapper is provided as precompiled MEX file for Windows®.
Example MATLAB calls
% Call to match Ti with Mi-1 >> [ Pi, niter, md, Oindx, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); % slower, ideal for SLAM (create Mi ) >> [ Pi, niter, md, Oindx, Ocoords, tTi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); >> [ Pi, niter, md, Oindx, Ocoords ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); >> [ Pi, niter, md ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); >> [ Pi, niter] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); % faster >> [ Pi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1, Outlierthreshold ); % ideal for mobile robot self-localization, Pi = ( xi, yi, θi ) >> [ Pi ] = SLAMICP( M, Ti, inlierthreshold, method, maxiter, Pi-1 ); % Outlierthreshold = inlierthreshold
% Display the help and usage instructions
>> SLAMICP( );
% Obtain the outliers of tTi (transformed Ti according to Pi ), matching and merging only the outliers of tTi (listed in Ocoords ) with Mi-1 (no ICP iterations) to create Mi >> [ ~, ~, ~, Oindex, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, inlierthreshold, method, 0, Pi, Outlierthreshold );
% Obtain the outliers of tTi (transformed Ti according to Pi )
>> [ ~, ~, ~, Oindex, Ocoords, tTi ] = SLAMICP( M, Ti, inlierthreshold, method, 0, Pi, Outlierthreshold );
% Obtain tTi (transformed Ti according to Pi ) and merge all points of tTi (all are outliers because Outlierthreshold = 0 ) with Mi-1 (no ICP iterations) to create Mi >> [ ~, ~, ~, Oindex, Ocoords, tTi, Mi ] = SLAMICP( Mi-1, Ti, 0, method, 0, Pi, 0 );
% Obtain tTi (transformed Ti using Pi )
>> [ ~, ~, ~, ~, ~, tTi ] = SLAMICP( M, Ti, 0, method, 0, Pi );
Download SLAMICP V4.1 version
16-05-2023: SLAMICP_V41.rar - First version published online ( includes a precompiled MEX file for MATLAB under Windows® )
Authors
Eduard Clotet & Jordi Palacín
Related papers
Main paper featuring the SLAMICP Library (please add citation if you use the library):