floodFill
fills a connected component starting from a
seed point with a specified color.
floodFill(
image,
seed = c(1, 1),
color = "white",
lo_diff = 0,
up_diff = 0,
connectivity = 4
)
An Image
object.
A 2-element vector indicating the x and y coordinates of the seed point from where to start the filling.
A value or vector of any kind of R color specification
compatible with col2bgr
representing the color of the border
(default: "white").
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 in image
. If it is shorter, its elements will be recycled.
If it has more, only the first n
elements will be used.
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 in image
. If it is shorter, its elements will be recycled.
If it has more, only the first n
elements will be used.
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).
This function returns the number of pixels that were filled and
modifies image
in place.
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] <U+2212> lo_diff <= image[x,y] <= image(seed$x,seed$y) + up_diff
where image[x<U+2032>,y<U+2032>] 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.
# NOT RUN {
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
floodFill(dots, color = "green")
# }
Run the code above in your browser using DataLab