bundles / skimage latest / skimage / morphology / _flood_fill / flood
function
skimage.morphology._flood_fill:flood
source: /dev/scikit-image/src/skimage/morphology/_flood_fill.py :129
Signature
def flood ( image , seed_point , * , footprint = None , connectivity = None , tolerance = None ) Summary
Mask corresponding to a flood fill.
Extended Summary
Starting at a specific seed_point, connected points equal or within tolerance of the seed value are found.
Parameters
image: ndarrayAn n-dimensional array.
seed_point: tuple or intThe point in
imageused as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.footprint: ndarray, optionalThe footprint (structuring element) used to determine the neighborhood of each evaluated pixel. It must contain only 1's and 0's, have the same number of dimensions as
image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).connectivity: int, optionalA number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is less than or equal to
connectivityare considered neighbors. Ignored iffootprintis not None.tolerance: float or int, optionalIf None (default), adjacent values must be strictly equal to the initial value of
imageatseed_point. This is fastest. If a value is given, a comparison will be done at every point and if within tolerance of the initial value will also be filled (inclusive).
Returns
mask: ndarrayA Boolean array with the same shape as
imageis returned, with True values for areas connected to and equal (or within tolerance of) the seed point. All other values are False.
Notes
The conceptual analogy of this operation is the 'paint bucket' tool in many raster graphics programs. This function returns just the mask representing the fill.
If indices are desired rather than masks for memory reasons, the user can simply run numpy.nonzero on the result, save the indices, and discard this mask.
Examples
from skimage.morphology import flood image = np.zeros((4, 7), dtype=int) image[1:3, 1:3] = 1 image[3, 0] = 1 image[1:3, 4:6] = 2 image[3, 6] = 3 image✓
mask = flood(image, (1, 1)) image_flooded = image.copy() image_flooded[mask] = 5 image_flooded✓
mask = flood(image, (1, 1), connectivity=1) image_flooded = image.copy() image_flooded[mask] = 5 image_flooded✓
mask = flood(image, (0, 0), tolerance=1) image_flooded = image.copy() image_flooded[mask] = 5 image_flooded✓
Aliases
-
skimage.morphology.flood