Connected-Components Labeling on a Raster

Identifying and labeling connected regions of foreground cells in a 2D raster grid, as the first step in converting raster airspace data (weather hazards, restricted zones) into polygon features for routing.

Step 1 of 157%

Tutorial

Rasters, Foreground Cells, and Connectivity

A raster is a regular 2D grid of cells. In airspace data, each cell encodes whether a hazard (storm, restricted zone, no-fly area) occupies that grid square — typically 11 for foreground (hazard present) and 00 for background (clear).

A connected component is a maximal set of foreground cells in which every cell can be reached from every other through a chain of neighbor-to-neighbor steps. The result depends on what we count as a neighbor:

  • 4-connectivity: each cell's neighbors are the 4 cells sharing an edge — N, S, E, W.
  • 8-connectivity: those 4 plus the 4 diagonal cells — NE, NW, SE, SW.

Consider the raster

R=[101110011].R = \begin{bmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \end{bmatrix}.

Under 4-connectivity, the cell at row 00, column 22 has only background edge-neighbors, so it is its own component. The other five foreground cells form one connected chain through shared edges. This gives 2 components.

Under 8-connectivity, the cell at (0,2)(0,2) is diagonally adjacent to (1,1)(1,1), which links it into the main chain. All six foreground cells now form a single component. This gives 1 component.

The choice of connectivity is a modeling decision: 4-connectivity treats diagonal-only contacts as not connected, which is often appropriate for hazard rasters where corner-touching cells should be split into separate features.

navigate · Enter open · Esc close · ⌘K/Ctrl K toggle