skimage 0.17.2

NotesParametersReturnsBackRef
flood(image, seed_point, *, selem=None, connectivity=None, tolerance=None)

Starting at a specific :None:None:`seed_point`, connected points equal or within tolerance of the seed value are found.

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.

Parameters

image : ndarray

An n-dimensional array.

seed_point : tuple or int

The point in :None:None:`image` used as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.

selem : ndarray, optional

A 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 :None:None:`image`. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).

connectivity : int, optional

A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is larger or equal to :None:None:`connectivity` are considered neighbors. Ignored if selem is not None.

tolerance : float or int, optional

If None (default), adjacent values must be strictly equal to the initial value of :None:None:`image` at :None:None:`seed_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 : ndarray

A Boolean array with the same shape as :None:None:`image` is returned, with True values for areas connected to and equal (or within tolerance of) the seed point. All other values are False.

Mask corresponding to a flood fill.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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 array([[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 2, 2, 0], [0, 1, 1, 0, 2, 2, 0], [1, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, with full connectivity (diagonals included):

This example is valid syntax, but we were not able to check execution
>>> mask = flood(image, (1, 1))
... image_flooded = image.copy()
... image_flooded[mask] = 5
... image_flooded array([[0, 0, 0, 0, 0, 0, 0], [0, 5, 5, 0, 2, 2, 0], [0, 5, 5, 0, 2, 2, 0], [5, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, excluding diagonal points (connectivity 1):

This example is valid syntax, but we were not able to check execution
>>> mask = flood(image, (1, 1), connectivity=1)
... image_flooded = image.copy()
... image_flooded[mask] = 5
... image_flooded array([[0, 0, 0, 0, 0, 0, 0], [0, 5, 5, 0, 2, 2, 0], [0, 5, 5, 0, 2, 2, 0], [1, 0, 0, 0, 0, 0, 3]])

Fill with a tolerance:

This example is valid syntax, but we were not able to check execution
>>> mask = flood(image, (0, 0), tolerance=1)
... image_flooded = image.copy()
... image_flooded[mask] = 5
... image_flooded array([[5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 5, 2, 2, 5], [5, 5, 5, 5, 2, 2, 5], [5, 5, 5, 5, 5, 5, 3]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.morphology._flood_fill.flood

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/morphology/_flood_fill.py#124
type: <class 'function'>
Commit: