Skip to content

03 Road-edge alignment (Step 2)

Entry function:

from trajlab.processing.alignment import AlignmentParams, align_lateral_positions

tracks = align_lateral_positions(tracks, params=AlignmentParams(target_offset_m=2.0)).tracks

Purpose

A data-derived reference line follows the road only up to its smoothing tolerance, and real roads curve. After projection the lanes are therefore not horizontal in d: a vehicle driving straight along its lane shows a slowly varying pos_lat. The alignment subtracts the right road edge, estimated from the data, so that every lane has an (approximately) constant lateral position along s.

before alignment                         after alignment
 d │   ~~~~~~~~ lane 2                    d │   -------- lane 2
   │   ~~~~~~~~ lane 1                      │   -------- lane 1
   │  __________ 5 % profile                │  __________ 5 % profile at 2.0 m (lane 1)
   └──────────────────── s                  └──────────────────── s

Interface

Pipeline step Requires columns Produces columns Further output columns
alignment pos_lon, pos_lat pos_lat_raw y_correction

pos_lat_raw keeps the value before alignment, y_correction the subtracted profile; pos_lat is replaced by the aligned value.

Parameter Default Description
alignment.enabled True Run the step.
alignment.km_step 10 Longitudinal bin width of the road-edge profile in meters.
alignment.smoothing_sigma_m 30 Gaussian smoothing sigma of the profile in meters.
alignment.quantile 0.05 Quantile (0-1) of pos_lat per bin that defines the right road edge.
alignment.target_offset_m 2 Lateral position in meters the road-edge profile is moved to (center of lane 1).
alignment.edge_freeze_m 0 Length in meters at each end of the profile frozen to the first interior value; 0 disables the freeze. Defaults to 0.0 m (no freeze; a 100 m freeze leaves the reference-line deviation at the ends uncorrected and raises the lane-change density there).
alignment.edge_freeze_bins None Legacy setting in bins; overrides edge_freeze_m if set.
alignment.profile_classes None Classes whose positions define the road-edge profile (e.g. ["Car"]: not displaced by perspective); the profile is applied to all rows. Defaults to None (all rows).

The alignment also reads lanes.auxiliary_lane_zones, lanes.lane_count_zones, lanes.n_main_lanes and the nominal lane width lanes.gmm_prior_eta_m (06).

Method

  1. Edge profile: in bins of km_step (10 m) along s, the quantile (5 %) of pos_lat, robust against single outliers beyond the edge, yet close to the right road edge.
  2. Auxiliary-lane zones: inside an AuxLaneZone the lowest band is the auxiliary lane, not the edge of the main carriageway. Bins overlapping a zone widened by one bin on each side are replaced by linear interpolation over s (with longitudinal noise a few auxiliary-lane points spill into the bin just before the zone; its low quantile would become the interpolation anchor and tilt the frame across the whole zone by up to 3 m).
  3. Lane-count zones on the right side (LaneCountZone(side="right")): where lanes are added or missing on the right, the road edge moves by whole lanes. The profile is referred back to the cross-section of n_main_lanes: $y(s) \leftarrow y(s) - w(s)\,(n_{main} - n_{zone}) \cdot 3.75$ m, with $w$ ramping linearly from 0 to 1 over taper_m before the zone and back after it. Without this the frame follows the moving edge and every lane is renumbered. Left-side zones need no compensation.
  4. Edge freeze: the first/last edge_freeze_m keep the value of the first interior bin. Default 0 m (see the design choices).
  5. Smoothing: 1-D Gaussian with $\sigma$ = smoothing_sigma_m / km_step (30 m / 10 m = 3 bins).
  6. Subtraction: $d \leftarrow d - y(s) + $ target_offset_m (2.0 m), i.e. the edge profile is moved to the center of lane 1.

Design choices

The choices below are made for this library unless a paper is named; the evidence for each is given under "Source" (a test, a script of applications/ant2027/ or a measurement named in the text).

  • No edge freeze by default (0 m). Apparent lane changes at the road ends come from the reference line leaving the road there, not from the traffic: the whole cross-section bends, and a frozen profile keeps that deviation uncorrected. The edge lane-change density stays ≤ 2× the interior in 30 of 44 directions at 0 m, 21 at 50 m and 7 at 100 m (median ratio 1.38 / 2.16 / 10.7). Events near the ends are flagged near_road_end (07) instead. Source: edge-freeze scan on 22 recordings, applications/ant2027/text_numbers/refline_edges.py; tests/processing/test_processing.py (edge freeze).
  • Auxiliary-lane zones are bridged one bin beyond each end. Without the extra bin the alignment tilts the frame inside the zone (see Method, step 2), and every lane label in the zone shifts by one. Synthetic merge family at 10 Hz: per-point accuracy 81 % → 99.9 % (minimum over 8 seeds, two rates and two noise levels). No effect without zones. Source: tests/processing/test_conventions.py (regression test, 3.02 m tilt without the margin).
  • Right-side lane-count zones shift the reference by whole lanes, with a taper. On the right the road edge itself moves when a lane is added or dropped. Without the compensation the per-point accuracy of right-side gains and drops falls to 44–50 % (every lane renumbered); with it 99.6–100 %. Left-side zones do not move the right edge and need no compensation. Source: tests/processing/lanes/test_lane_count_zones.py.

Validation and limitations

  • tests/processing/test_conventions.py (constant shift on a straight road, also inside auxiliary-lane zones; regression test for the bridging margin), tests/processing/test_processing.py (edge freeze), tests/processing/lanes/test_lane_count_zones.py (right-side drop/gain, taper).
  • Samples outside the carriageway (ramps beyond the gore) pull the edge by up to several meters; crop the input to the carriageway.
  • In one direction of campaign 1b the edge lane-change density at one section end stays 20–34× the interior (a ramp or the edge of the camera view; not resolved).