Skip to content

06 Lane geometry (Step 4)

Entry function:

from trajlab.processing.lanes import estimate_lane_geometry
from trajlab.road_layout import LaneLayout

result = estimate_lane_geometry(tracks, layout=LaneLayout(n_main_lanes=3))
tracks, centers = result.tracks, result.centers

Purpose

Lane centers are estimated from the data instead of being drawn by hand: in rolling windows along the road a Gaussian mixture is fitted to the lateral positions of cars, and the window centers are tracked along the road. Every point gets the nearest lane (lane); Step 5 turns these per-point labels into consistent per-vehicle lane sequences.

Interface

Pipeline step Requires columns Produces columns Further output columns
lanes id, datum, pos_lon, pos_lat lane —

Lane IDs: 1 = rightmost main lane of the widest cross-section, increasing to the left; 0 = auxiliary lane inside configured zones; -1 = unassigned. Context artifacts: lane_centers (tracked centers per window), lane_geometry_diagnostics (lost-lane windows, center spread; also in the run metadata lane_geometry).

Parameter Default Description
lanes.enabled True Run the step.
lanes.n_main_lanes 3 Lanes of the main carriageway (without auxiliary lanes); upper bound for the GMM component count.
lanes.auxiliary_lane_zones [] Sections with an auxiliary lane (lane 0), in pos_lon meters. Also used by the alignment.
lanes.lon_step_m 50 Step between rolling GMM window centers in meters.
lanes.window_size_m 200 Longitudinal width of each GMM window in meters.
lanes.max_drift_m 2 Maximum lateral drift in meters when matching lane centers between windows.
lanes.assignment_method 'hmm' How Step 5 turns the Step 4 labels into lane_fixed: "heuristic" (crossovers of the detected lane changes, piecewise-constant segments, frame-wise conflict re-assignment) or "hmm" (hidden Markov model, processing.lanes.hmm).
lanes.hmm *(section)* Parameters of the "hmm" method; a dict is converted. Defaults to HmmConfig().
lanes.resolve_conflicts True Cross-vehicle conflict resolution of Step 5 (heuristic: frame-wise re-assignment of overlapping vehicles and edge snapping; HMM: feasibility re-decoding). Off only for evaluation (to measure the effect of the resolution).
lanes.keep_unresolved_lane False Also output lane_fixed_unresolved, the Step 5 labels before the conflict resolution (evaluation).
lanes.gmm_model 'restricted' Step 4 mixture per window: "restricted" (default; Chen & Krumm 2010: n_main_lanes equally spaced components with one shared variance, MAP-EM with priors; plus a free auxiliary-lane component in zones) or "free" (GMM with 1..n_main_lanes free components, BIC selection; the original behavior).
lanes.gmm_prior_eta_m 3.75 "restricted": prior mean of the lane spacing (nominal lane width).
lanes.gmm_prior_kappa 100 "restricted": prior strength of the spacing, dmu \| sigma2 ~ N(eta, sigma2 / kappa).
lanes.gmm_prior_nu 3 "restricted": shape parameter of the variance prior sigma2 ~ Inv-Gamma(nu / 2, varsigma2 / 2).
lanes.gmm_prior_varsigma2_m2 0.25 "restricted": scale of that prior (m^2; prior mean of sigma2 = varsigma2 / (nu - 2)). Defaults to 0.25 (Chen & Krumm: 4 m^2 for GPS; drone positions have centimetre noise).
lanes.lane_count_zones [] Sections with a different number of main lanes (lane gain/drop); dicts are converted. Step 4 uses the local lane count per window (exact for "restricted", upper bound for "free"), lanes that end are removed from tracking at once and not extrapolated, and the HMM allows a lane only where Step 4 has a center for it. Defaults to none (n_main_lanes everywhere).

Zones are configured per site (in the lanes section; examples in the package site files trajlab/config/sites/*.yaml, trajlab.config.load_site(name)):

  • AuxLaneZone(lon_start, lon_end, kind), kind ∈ on_ramp, off_ramp, acceleration, deceleration, weaving (one auxiliary lane from an on-ramp to the next off-ramp): a section with an auxiliary lane (lane 0) right of lane 1. The kind documents the zone; the steps treat every kind alike.
  • LaneCountZone(lon_start, lon_end, n_lanes, side="left"|"right", taper_m=0): a section with a different number of main lanes (lane gain or drop).

Method

Windows and fit data

Windows of window_size_m (200 m) every lon_step_m (50 m). The fit uses the pos_lat of cars (all vehicles if fewer than 30 car points). Inside auxiliary-lane zones, points right of lane 1 (its center minus half the local lane width) are left out of the fit and labeled 0.

Restricted GMM (default, gmm_model = "restricted")

Chen & Krumm (2010, ACM SIGSPATIAL GIS, 81–88): exactly $k$ = number of main lanes components (from the site configuration and lane-count zones, no model selection) with equally spaced means and one shared variance,

$$p(d) = \sum_{j=1}^{k} w_j\,\phi!\left(d \mid \mu + (j-1)\Delta\mu,\ \sigma^2\right).$$

MAP estimation by EM as in their Appendix A, priors: $w_j$ and $\mu$ uniform, $\sigma^2 \sim \text{Inv-Gamma}(\nu/2, \varsigma^2/2)$, $\Delta\mu \mid \sigma^2 \sim N(\eta, \sigma^2/\kappa)$.

  • E-step: $\gamma_{ij} \propto w_j\,\phi(d_i \mid \mu_j, \sigma)$, $n_j = \sum_i \gamma_{ij}$.
  • M-step: $w_j = n_j / n$; $(\mu, \Delta\mu)$ from $\begin{pmatrix}\sum n_j & \sum c_j n_j\ \sum c_j n_j & \sum c_j^2 n_j + \kappa\end{pmatrix}\begin{pmatrix}\mu\ \Delta\mu\end{pmatrix} = \begin{pmatrix}\sum_i d_i\ \sum_{ij}\gamma_{ij} c_j d_i + \kappa\eta\end{pmatrix}$, $c_j = j-1$; $\sigma^2 = \big(\varsigma^2 + \kappa(\Delta\mu - \eta)^2 + \sum_{ij}\gamma_{ij}(d_i - \mu_j)^2\big)/(n + \nu + 3)$.
  • Priors: $\eta$ = 3.75 m (nominal lane width), $\kappa$ = 100, $\nu$ = 3 as in the paper; $\varsigma^2$ = 0.25 m² instead of their 4 m² (prior mean of $\sigma^2$ = $\varsigma^2/(\nu-2)$; their value reflects GPS noise, ours the lane-keeping spread plus the centimetre noise of drone positions).
  • Start values: EM is run from the warm start (previous window with the same lane count) and from a grid search over $\mu$ with $\Delta\mu = \eta$; the solution with the higher log posterior is kept (see the design choices).
  • Auxiliary lane (addition, not in the paper): in windows touching an auxiliary-lane zone one extra component right of lane 1 with its own mean and variance (same variance prior, flat prior on its mean), outside the spacing constraint (auxiliary lanes are often narrower).

Implementation: processing/lanes/geometry.fit_restricted_gmm, checked line by line against Appendix A.

Joint mixture with an HGV offset (used by perspective.correction = "joint_gmm")

processing/perspective/joint_offset.fit_restricted_gmm_joint extends the restricted GMM by a second class that shares the lane centers: HGV points follow $\sum_j v_j N(\mu_j + \delta_j, \sigma_h^2)$ with their own lane weights and variance and an offset $\delta$ (scalar or per lane). It is used only by the perspective step to estimate the offset (02); Step 4 itself is unchanged (cars only, plain restricted GMM). With delta fixed the fit is the window step of the outer offset update; joint_log_posterior evaluates the same posterior for tests.

Free GMM (gmm_model = "free", the earlier default)

scikit-learn GMM with 1…n_main_lanes free components (+1 in windows touching a zone; the rightmost is then the auxiliary lane), chosen by BIC; components closer than 2.5 m are rejected. Can drop components (e.g. a lane without cars in a window; the lane is then "lost") but never exceeds n_main_lanes outside zones.

Tracking and labeling

Window centers are matched to the tracked lanes with the Hungarian algorithm (cost = lateral distance, maximum drift max_drift_m = 2 m); matched lanes are updated as $y \leftarrow 0.7\,y + 0.3\,m$; unmatched lanes follow the mean shift of the matched ones and are dropped after 10 missed windows. Every point gets the nearest active center of its 50 m bin. Raw tracking IDs are renumbered by lateral order (collapse_and_standardize_lanes; 1-D KMeans if more raw lanes than the maximum lane count).

Lane gain and lane drop (lane_count_zones)

Per window the main-lane count at the window center (n_main_lanes outside the zones): exactly that many components for restricted, at most that many for free. Tracked lanes left without a center where the count drops are removed at once (no phantom lane), and centers are back-filled over at most one window (a lane that starts later must not appear earlier). Lane numbers stay those of the widest cross-section; a lane that ends keeps its number. Right-side zones also shift the alignment reference (03); the HMM allows a lane only within its observed range (09).

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).

  • Restricted GMM as the default instead of the free GMM. The free GMM chooses the number of components by BIC and drops a sparsely used lane in windows with few vehicles; the restricted model knows the lane count and cannot lose a lane. On Sites 1 and 2 (44 directions, with HGV correction) lost-lane windows fall from 3.1 % to 0.06 % at unchanged in-lane overtakings (7.37 → 7.31 per 100 vehicle-km); on a synthetic sparse lane the free GMM loses the lane in up to 55 % of the windows. Source: Chen & Krumm (2010); tests/processing/lanes/test_restricted_gmm.py.
  • Variance prior ς² = 0.25 m² instead of Chen & Krumm's 4 m². Their prior describes GPS noise of several meters; drone positions have centimetre noise, and the lane-keeping spread dominates. Source: Chen & Krumm (2010), Appendix A.
  • EM from two starts, the higher posterior kept. A warm start from the previous window alone can lock into a local optimum: after a short common lateral shift at a camera hand-over it kept a 2.1 m spacing although the car density peaks show lanes 3.75 m apart along the whole section. The additional grid start removes this.
  • Lane-count zones with fixed lane numbers. Neither GMM handles a configured change in the number of main lanes: the restricted model needs the count, the free one never exceeds n_main_lanes. Lane numbers stay those of the widest cross-section so that a lane keeps its number through a gain or drop. Without zones right-side changes fall to 44–50 % accuracy; with them all combinations reach ≥ 99.6 %. Source: tests/processing/lanes/test_lane_count_zones.py.
  • Zone-aware windows. In windows touching an auxiliary-lane zone the fit allows one extra component (restricted: a free auxiliary component; free: up to n_main + 1, the rightmost dropped if all are used). Otherwise a zone at the start of the section takes a main-lane component before any lane is known. No effect without zones.

Validation and limitations

  • tests/processing/lanes/test_restricted_gmm.py (parameter recovery, auxiliary component, sparse lane 3 over 5 seeds × 2 shares, merge family ≥ 95 % at 10 Hz), tests/processing/lanes/test_lane_count_zones.py (left/right gain/drop for both models and both Step 5 methods ≥ 99.6 %; right-side changes without zones 44–50 %).
  • Sites 1 and 2 (44 directions, with HGV correction): lost-lane windows 3.1 % (free) → 0.06 % (restricted); in-lane overtakings 7.37 → 7.31 per 100 vehicle-km; center spread 0.23 → 0.22 m. Synthetic sparse lane: free loses lane 3 in up to 55 % of the windows (center errors up to 0.49 m), restricted never (≤ 0.18 m).
  • Restricted presupposes the HGV correction on HGV-rich data: without it in-lane overtakings rise (one recording of campaign 1b).
  • The lane count must be known per section; it is not detected automatically (Chen & Krumm's spread regulariser for selecting k is not implemented).