Skip to the lesson
FixTheRobot Explore Robotics / Localization & SLAM / M5 LiDAR SLAM / M5-T2

Localization & SLAM · Theory · M5

M5-T2 — Point-Cloud Preprocessing

Throw away what does not help, fix what is distorted, and thin what is redundant, in that order.

  • Lesson 2 of 11
  • Module 5: LiDAR SLAM
  • Theory
  • About 8 minutes to read

Raw LiDAR scans are too big, too noisy and too distorted for registration. Every LiDAR SLAM system runs the cloud through a short preprocessing chain before anything else, and its choices (a voxel size, a range limit, a ground threshold) have more influence on accuracy and speed than most of the choices in the algorithm that follows. This lesson walks through each stage and the mistakes that cost the most.

Learning objectives

After this lesson, you should be able to:

  • Apply range filtering, deskewing, ground removal and voxel downsampling in a sensible order.
  • Compute a voxel-grid centroid and estimate the point reduction for a given voxel size.
  • Fit a ground plane with RANSAC and explain its failure on slopes and stairs.
  • Say what each stage costs and what it can destroy.

The problem and the intuition

Think of preparing vegetables before cooking: peel what is inedible (blind-zone and far-away noise), straighten what got bent in the bag (deskew), set aside the part you will treat differently (the ground), and cut everything to a similar size so it cooks evenly (voxel filter). Done in the wrong order, or too aggressively, you spoil the dish: thin the cloud before deskewing and you bake the distortion in; remove the “ground” in a hilly park and you remove half the world.

Preprocessing is not neutral. Every parameter is a modelling decision about what the environment looks like.

A preprocessing pipelineFive stages in sequence: range filter removes the sensor’s blind zone and far noise, deskewing places each point with the pose at its own time, ground removal separates floor points, voxel downsampling reduces density to a fixed resolution, and the result goes to registration. Counts fall from 130 thousand to 8 thousand points.Raw scan130,000 points Range filter0.8 – 60 m Deskewpose per point Groundsplit floor Voxel filter8,000 points Each stage costs time and risks removing information; order matters. Deskewing must happen before the voxel filter and before any feature search.
A typical chain and its effect on the number of points. The order matters: deskew before thinning, filter by range before the plane fit.

The algorithm: the preprocessing chain

Problem. Turn a raw scan of 10⁴–10⁵ points, distorted by motion and containing noise and the sensor’s own body, into a small clean cloud that a registration algorithm can match in milliseconds.

Assumptions. Per-point times (or a motion estimate for the sweep) are available; the ground is approximately planar near the robot; the interesting geometry is within a sensible range.

Pipeline

  1. Range filter. Remove points with range below rmin (the robot’s body and the sensor’s dead zone, typically 0.5–1 m) and above rmax (where noise and sparsity make points useless: 40–100 m outdoors, 15–30 m indoors). Cheap; do it first.
  2. Deskew (M5-T1). For each point with sweep fraction s, apply the pose interpolated at s so that all points are in the frame of the scan start (or end). Needs per-point time and a motion estimate.
  3. Ground removal or segmentation. Fit a plane to the lowest points (RANSAC with a distance threshold of 5–10 cm), or use a ring-based or patch-based method (Patchwork). Ground points can be kept as a separate set of planar features (LeGO-LOAM, M5-T7) or removed to reduce the ground’s dominance.
  4. Voxel downsampling. Divide space into cubes of side ℓ; replace the points in each cube by their centroid. This makes the density uniform and the cloud small.
  5. Optional: statistical outlier removal (drop points whose mean distance to k neighbours is above μ + kσ), removal of dynamic or semantic objects (Module 8), and normal estimation.
Voxel-grid filter
centroid⁡(v)=(1/∣v∣) ∑p∈v p\operatorname{centroid}(v)=(1/\lvert v\rvert )\,\sum _{p\in v}\,p
voxel index=(⌊xℓ⌋, ⌊yℓ⌋, ⌊zℓ⌋)\text{voxel index}=(\frac{\lfloor x}{\ell \rfloor },\,\frac{\lfloor y}{\ell \rfloor },\,\frac{\lfloor z}{\ell \rfloor })
ℓ
voxel size. 0.1–0.5 m for large outdoor scenes, 0.05–0.2 m indoors.
|v|
the number of points in voxel v.
RANSAC plane
repeatedly fit a plane to 3 random points and keep the plane with the most inliers within a distance threshold.

What each stage costs and risks

Costs and risks of preprocessing stages
StageCostRisk if too aggressiveRisk if too weak
Range filterO(N), negligibleLoses distant structure that constrains the headingNoise and the robot’s body enter the map
DeskewO(N) with a pose lookup(none) wrong motion estimate gives a wrong correctionSystematic distortion; biased odometry
Ground removalRANSAC: ~1 msRemoves slopes, ramps and low obstacles; loses vertical constraintsThe ground dominates the registration and hides walls
Voxel filterO(N) with a hashRounds corners and thin structures (poles, wires)Too many points: slow, density bias toward near points

A worked example: voxels, planes and counts

  1. A voxel centroid. With ℓ = 0.5 m, the points (0.1, 0.2, 0.3), (0.3, 0.1, 0.1) and (0.2, 0.3, 0.2) all fall in the voxel (0, 0, 0). Their centroid is (0.2, 0.2, 0.2): three points become one, and the position is the average, which also reduces the noise by about √3.
  2. How many points remain? A 64-ring sensor with 2,048 azimuth steps gives 131,072 points per scan at 10 Hz, or 1.3 million points per second. A typical outdoor scan puts most points near the sensor: within 10 m the density at 5 m is about (ring spacing 0.4° × azimuth step 0.18°) → points every 3.5 cm vertically and 1.6 cm horizontally: 1,800 points per square metre of wall. With ℓ = 0.4 m the voxel contains up to 0.4² × 1,800 ≈ 290 points: a 100-fold reduction near the sensor, almost none at 60 m, so the density becomes nearly uniform. The final cloud has about 8,000–15,000 points.
  3. Ground plane by RANSAC. Take the points below z = −1.5 m (the sensor is 1.8 m above the ground). Fit planes from random triples; the best has 9,500 inliers within 8 cm and normal (0.01, 0.00, 1.00): the ground is horizontal within 0.6°. Removing those points leaves walls, poles and vehicles.
  4. On a ramp with a 10° slope the best plane has 40% of the inliers and a normal tilted by 10°; a threshold set to “ground = plane within 5° of horizontal” would reject it and keep the ramp as an obstacle. The decision of what is ground is part of the model.
  5. Order matters. If the voxel filter runs before deskewing, the centroid of a voxel mixes points from times 0 and 0.1 s, locking the 20 cm distortion into the point positions; deskewing after cannot separate them. Always deskew first, then thin.

The lab asks you to repair a smeared and slow map by fixing exactly these three things.

Engineering implications and limitations

Engineering implications

  • Choose the voxel size by the geometry you need to register: 2–3× the typical noise is a minimum; the structures that anchor the pose (walls, poles) must survive it. Many systems use two sizes: fine for the local map, coarser for fast scan-to-scan.
  • Keep the original for mapping. Registration can use a thinned cloud while the saved map uses the full-resolution, deskewed points with the optimised pose.
  • Use a hash map for voxels (PCL VoxelGrid, Open3D, a hand-written hash) to keep the cost linear. Sorting-based implementations are slower.
  • Make ground handling explicit. If the vehicle drives on flat ground, treat ground points as constraints on z, roll and pitch (LeGO-LOAM); if it drives on rough terrain, do not assume a plane.
  • Mask the robot. A bounding box in the sensor frame removes the robot’s own body; leaving it in is a common reason for a map that follows the robot.
  • Measure time. Preprocessing should be a few milliseconds. If it is more than the registration, something is off (a dense cloud, a dense voxel size, a slow plane fit).

Limits

All these steps are heuristics tuned to a scene type. A voxel size good in a corridor removes the detail of a forest; a ground model good in a car park fails on stairs; a range limit suited to a warehouse throws away the long views that stabilise the heading in an open field. Parameters should be exposed and logged, and checked when the environment changes. Learned or adaptive filtering is an active area (Module 8).

Common misconceptions

“Downsampling only affects speed.”

It changes what the registration sees: density bias toward near surfaces, rounded corners, and the loss of fine features that constrain the pose.

“The ground should always be removed.”

It carries information about height, roll and pitch. Removing it blindly loses constraints (and on slopes loses the ground itself).

“Deskewing can be done later.”

Once points are merged or thinned the per-point time is lost; the distortion is baked in.

“A larger range is always better.”

Far points are noisy and sparse; they cost time and add bias. Choose the range for the scene.

Engineering takeaways

  1. The standard chain is range filter, deskew, ground handling, voxel downsampling; the order matters.
  2. A voxel filter replaces the points of each cube by their centroid, making density uniform and the cloud small.
  3. RANSAC plane fitting finds the ground in a few milliseconds but fails on slopes unless the model allows tilt.
  4. Each stage has a cost and can destroy information; its parameters are modelling decisions about the scene.
  5. Keep full-resolution deskewed data for the map; register on the thinned cloud.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

A pipeline voxel-filters the cloud with ℓ = 0.5 m and then deskews. What goes wrong?

Explanation

Points from different times in the sweep are merged into one centroid, and the per-point times are lost, so the deskewing step cannot apply the right correction to each. The distortion is baked into the centroids. Deskew first, then voxel-filter.

Question 2

A robot is moved from a flat warehouse onto a ramp, and its mapping starts to drift in height. The pipeline removes the ground with a horizontal-plane RANSAC. What is the likely connection?

Explanation

On the ramp the ground plane is tilted and may be rejected as “not ground” or only partly removed. The registration then loses the ground’s constraint on z, roll and pitch, or is dominated by a sloped surface it treats as a wall. Use a ground model that allows tilt, or do not segment the ground.

Question 3

Why does a voxel filter with a fixed ℓ make the point density more uniform, and why does that help registration?

Explanation

Near the sensor many points fall in each voxel and are averaged to one, while far points are mostly alone, so the output has about one point per voxel everywhere. Registration then weights near and far structure evenly instead of being dominated by the dense nearby surfaces, and the nearest-neighbour search is cheaper.

What’s next

Next, the step that picks which of the remaining points to match: LOAM-style feature extraction from the smoothness of the scan line.

Practice this lesson

Fix Point-Cloud Preprocessing

A map is smeared and slow: repair deskewing, ground removal and downsampling.

Next lesson

M5-T3 — Feature Extraction

Compute LOAM-style smoothness to select edge and planar features and understand why selection helps.

Nothing below is required to finish this lesson.