environmentaltools.processes.flood_fill

environmentaltools.processes.flood_fill(c, r, mask)[source]

Perform flood fill algorithm on a binary mask to identify connected regions.

Implements a non-recursive 8-way connectivity flood fill algorithm. Starting from a seed cell, identifies all connected cells with value 1 in the mask. Useful for delineating inundation areas or connected coastal regions.

Parameters:
  • c (int) – Starting column index (x-coordinate)

  • r (int) – Starting row index (y-coordinate)

  • mask (np.ndarray) – Binary 2D array containing only 1 and 0 values, where 1 represents cells to potentially fill

Returns:

Binary array of same shape as mask, with 1 values for all cells connected to the starting point, 0 elsewhere

Return type:

np.ndarray

Notes

This algorithm uses 8-way connectivity (includes diagonal neighbors). It’s non-recursive to avoid stack overflow issues with large connected regions.

The algorithm is commonly used for:

  • Identifying inundation extents from water level data

  • Finding connected coastal segments

  • Delineating watersheds or drainage basins

Complexity: O(n) where n is the number of connected cells