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.
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 for foreground (hazard present) and 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
Under 4-connectivity, the cell at row , column 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 is diagonally adjacent to , 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.