floodFill
fills a connected component starting from a
seed point with a specified color.
Usage
floodFill(
image,
seed = c(1, 1),
color = "white",
lo_diff = 0,
up_diff = 0,
connectivity = 4
)
Arguments
- image
An
Image
object.- seed
A 2-element vector indicating the x and y coordinates of the seed point from where to start the filling.
- color
A value or vector of any kind of R color specification compatible with
col2bgr
representing the color of the border (default: "white").- lo_diff
Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component (see Details). It can be a single value or a vector of the same length as the number
n
of channels inimage
. If it is shorter, its elements will be recycled. If it has more, only the firstn
elements will be used.- up_diff
Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component (see Details). It can be a single value or a vector of the same length as the number
n
of channels inimage
. If it is shorter, its elements will be recycled. If it has more, only the firstn
elements will be used.- connectivity
The connetivity neighborhood to decide whether 2 pixels are contiguous. This parameter can take two values:
- 4:
the neighborhood of a pixel are the four pixels located above (north), below (south), to the left (west) and right (east) of the pixel.
- 8 (the default):
the neighborhood of a pixel includes the four 4-neighbors and the four pixels along the diagonal directions (northeast, northwest, southeast, and southwest).
Details
The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at (x,y) is considered to belong to the repainted domain if:
in case of a floating range:
image[x',y'] - lo_diff <= image[x,y] <= image[x',y'] + up_diff
in case of a fixed range:
image[seed$x,seed$y] − lo_diff <= image[x,y] <= image(seed$x,seed$y) + up_diff
where image[x′,y′] is the value of one of pixel neighbors that is already known to belong to the component. That is, to be added to the connected component, a color/brightness of the pixel should be close enough to:
Color/brightness of one of its neighbors that already belong to the connected component in case of a floating range.
Color/brightness of the seed point in case of a fixed range.
Author
Simon Garnier, garnier@njit.edu
Examples
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
floodFill(dots, color = "green")
#> [1] 128564