segmentation¶
occulus.segmentation
¶
Point cloud segmentation — ground classification and object extraction.
Primary interface::
from occulus.segmentation import (
classify_ground_csf,
classify_ground_pmf,
cluster_dbscan,
detect_powerlines,
segment_trees,
PowerlineResult,
SegmentationResult,
)
Ground classification
- :func:
classify_ground_csf— Cloth Simulation Filter (aerial/UAV preferred) - :func:
classify_ground_pmf— Progressive Morphological Filter
Object segmentation
- :func:
cluster_dbscan— density-based clustering (general purpose) - :func:
segment_trees— CHM-based individual tree delineation (aerial/UAV)
Infrastructure detection
- :func:
detect_powerlines— wire and pylon extraction from classified clouds
PowerlineResult
dataclass
¶
Result of powerline detection.
Attributes:
| Name | Type | Description |
|---|---|---|
wire_mask |
NDArray[bool_]
|
Per-point boolean mask identifying wire points. |
pylon_mask |
NDArray[bool_]
|
Per-point boolean mask identifying pylon/tower points. |
wire_segments |
list[CatenarySegment]
|
List of detected wire segments with optional catenary fits. |
pylon_positions |
NDArray[float64]
|
Centroid positions of detected pylons as (M, 3) array. |
clearance_violations |
list[ClearanceViolation]
|
Locations where wires are below the minimum clearance threshold. |
Source code in src/occulus/segmentation/powerlines.py
SegmentationResult
dataclass
¶
Result of object segmentation.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
NDArray[int32]
|
Per-point segment labels. |
n_segments |
int
|
Number of unique segments (excluding noise label -1). |
segment_sizes |
dict[int, int]
|
Mapping of label → point count (noise label excluded). |
Source code in src/occulus/segmentation/objects.py
classify_ground_csf(cloud, *, cloth_resolution=None, rigidness=3, iterations=500, class_threshold=None)
¶
Classify ground points using the Cloth Simulation Filter (CSF).
The cloud is inverted along Z, a regular cloth grid is draped over it under gravity, and the final cloth height is compared to the cloud to assign ground labels (ASPRS class 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Input point cloud. Must have at least 10 points. |
required |
cloth_resolution
|
float | None
|
Spacing between cloth grid nodes in coordinate units. Smaller values produce finer results at higher computational cost. Defaults to a platform-aware value (2.0 for aerial, 0.5 for terrestrial, 1.5 for UAV). |
None
|
rigidness
|
int
|
Cloth rigidness: 1 (mountain), 2 (complex terrain), 3 (flat terrain), by default 3. Higher values pull the cloth tighter to the surface. |
3
|
iterations
|
int
|
Maximum cloth simulation iterations, by default 500. |
500
|
class_threshold
|
float | None
|
Maximum distance between a point and the cloth surface for the point
to be classified as ground. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
PointCloud
|
Copy of the input cloud with |
Raises:
| Type | Description |
|---|---|
OcculusSegmentationError
|
If the cloud has fewer than 10 points or the simulation produces no ground points. |
Source code in src/occulus/segmentation/ground.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
classify_ground_pmf(cloud, *, cell_size=1.0, slope=0.3, initial_distance=0.15, max_distance=2.5, max_window_size=20.0)
¶
Classify ground points using the Progressive Morphological Filter (PMF).
Creates a series of morphological opening operations with progressively growing window sizes. Points that are too far above the morphologically opened surface are classified as non-ground.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Input point cloud. Must have at least 10 points. |
required |
cell_size
|
float
|
Grid cell size for the terrain surface, by default 1.0. |
1.0
|
slope
|
float
|
Slope tolerance in metres per metre (e.g. 0.3 = 30% grade), by default 0.3. |
0.3
|
initial_distance
|
float
|
Initial maximum distance threshold in metres, by default 0.15. |
0.15
|
max_distance
|
float
|
Maximum allowed height difference above the filtered surface, by default 2.5. |
2.5
|
max_window_size
|
float
|
Maximum morphological window radius in metres, by default 20.0. |
20.0
|
Returns:
| Type | Description |
|---|---|
PointCloud
|
Copy of the input cloud with |
Raises:
| Type | Description |
|---|---|
OcculusSegmentationError
|
If the cloud has fewer than 10 points or no ground points are found. |
Source code in src/occulus/segmentation/ground.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
cluster_dbscan(cloud, eps, min_samples=10, *, use_2d=False)
¶
Cluster a point cloud using DBSCAN.
Density-Based Spatial Clustering of Applications with Noise (DBSCAN) groups points that are closely packed together and marks outliers as noise (label -1). No prior knowledge of the number of clusters is needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Input point cloud. |
required |
eps
|
float
|
Neighbourhood radius: maximum distance between two points for them to be considered neighbours. In the same units as the cloud coordinates. |
required |
min_samples
|
int
|
Minimum number of points in a neighbourhood for a core point, by default 10. |
10
|
use_2d
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
SegmentationResult
|
Per-point labels and cluster statistics. |
Raises:
| Type | Description |
|---|---|
OcculusSegmentationError
|
If eps or min_samples are invalid, or the cloud is empty. |
Source code in src/occulus/segmentation/objects.py
detect_powerlines(cloud, *, min_height_above_ground=3.0, max_height_above_ground=50.0, linearity_threshold=0.7, ground_class=2, catenary_fit=True, min_clearance=None, strict=True, min_wire_span=50.0, max_pylon_xy_extent=5.0, min_pylon_z_extent=8.0, max_wire_height_std=3.0, pylon_association_radius=10.0)
¶
Detect powerline wires and pylons in a classified point cloud.
The algorithm:
- Separate ground (
ground_class) from non-ground using the cloud'sclassificationattribute. - Interpolate a ground surface and compute height-above-ground (HAG) for every non-ground point.
- Filter candidates by the HAG height band.
- Compute per-point geometric features (linearity, planarity, verticality) via PCA on local KDTree neighbourhoods.
- Classify wire candidates (high linearity) and pylon candidates (high verticality, low linearity, spatially clustered).
- Cluster wire candidates with DBSCAN into individual wire segments.
- Optionally fit catenary curves to each wire segment.
- Optionally flag clearance violations where wires are below
min_clearance.
When strict=True (the default), additional false-positive
reduction filters are applied:
- Wire segment length: DBSCAN clusters whose 3D extent is
shorter than
min_wire_spanare rejected (building edges, fences). - Pylon geometry: Pylon clusters whose XY bounding box exceeds
max_pylon_xy_extentor whose Z extent is less thanmin_pylon_z_extentare rejected (buildings, tree crowns). - Height band consistency: Wire clusters whose height standard
deviation exceeds
max_wire_height_stdare rejected (tree crowns with scattered points). - Wire–pylon association: Wire segments whose endpoints are
not within
pylon_association_radiusof a detected pylon are downgraded (removed from the confirmed wire mask but retained as segments withrmse=inf).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Input point cloud. Must have a |
required |
min_height_above_ground
|
float
|
Minimum height above the interpolated ground surface for a point to be considered a powerline candidate, by default 3.0. |
3.0
|
max_height_above_ground
|
float
|
Maximum height above ground, by default 50.0. |
50.0
|
linearity_threshold
|
float
|
Minimum linearity value (0--1) for a point to be classified as a wire candidate, by default 0.7. |
0.7
|
ground_class
|
int
|
ASPRS classification code for ground points, by default 2. |
2
|
catenary_fit
|
bool
|
If |
True
|
min_clearance
|
float | None
|
If provided, flag wire points whose HAG is below this value as
clearance violations, by default |
None
|
strict
|
bool
|
If |
True
|
min_wire_span
|
float
|
Minimum horizontal extent (metres) for a wire DBSCAN cluster to
be accepted. Only used when |
50.0
|
max_pylon_xy_extent
|
float
|
Maximum XY bounding box size (metres) for a pylon cluster.
Clusters wider than this are rejected as buildings. Only used
when |
5.0
|
min_pylon_z_extent
|
float
|
Minimum Z extent (metres) for a pylon cluster. Clusters shorter
than this are rejected. Only used when |
8.0
|
max_wire_height_std
|
float
|
Maximum standard deviation (metres) of Z values within a wire
cluster. Clusters exceeding this are rejected. Only used when
|
3.0
|
pylon_association_radius
|
float
|
Maximum distance (metres) from a wire segment endpoint to the
nearest pylon centroid for the segment to be considered
connected. Only used when |
10.0
|
Returns:
| Type | Description |
|---|---|
PowerlineResult
|
Detection results including wire/pylon masks, segments, pylon positions, and optional clearance violations. |
Raises:
| Type | Description |
|---|---|
OcculusSegmentationError
|
If the cloud has no classification array, too few ground points for interpolation, or no powerline candidates are found. |
Source code in src/occulus/segmentation/powerlines.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
segment_trees(cloud, *, resolution=1.0, min_height=2.0, min_crown_area=4.0, max_raster_size=5000)
¶
Segment individual trees using a CHM-based watershed approach.
Builds a 2D Canopy Height Model (CHM) raster from the input cloud, detects local maxima as tree tops, then performs a marker-controlled watershed segmentation to delineate individual tree crowns.
This function is intended for aerial or UAV clouds. Terrestrial clouds will raise an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Input cloud. Should be non-ground points (vegetation only) for best results. Must be aerial or UAV platform. |
required |
resolution
|
float
|
CHM raster resolution in coordinate units, by default 1.0. |
1.0
|
min_height
|
float
|
Minimum tree height above the minimum Z of the cloud, by default 2.0. |
2.0
|
min_crown_area
|
float
|
Minimum crown area in square coordinate units to retain a tree segment, by default 4.0. |
4.0
|
max_raster_size
|
int
|
Maximum allowed dimension (width or height) for the CHM raster. If the computed raster would exceed this in either dimension, the resolution is automatically coarsened to fit. By default 5000. |
5000
|
Returns:
| Type | Description |
|---|---|
SegmentationResult
|
Per-point tree labels. Label -1 = not assigned to any tree. |
Raises:
| Type | Description |
|---|---|
UnsupportedPlatformError
|
If the cloud platform is |
OcculusSegmentationError
|
If no trees are detected. |
Source code in src/occulus/segmentation/objects.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |