cv.floodFill - MATLAB File Help |
Fills a connected component with the given color
[dst, rect, area] = cv.floodFill(src, seed, newVal)
[dst, rect, area, mask] = cv.floodFill(..., 'Mask',mask, 'MaskOnly',true)
[...] = cv.floodFill(..., 'OptionName',optionValue, ...)
[x,y]
.src
.
Contains the modified input unless the MaskOnly
flag is set in the
second variant of the function, in which case dst
is the same as the
input src
unmodified. See the details below.[x,y,w,h]
.Mask
. Populated in
the second variant of the function with the Mask
option. On output,
pixels in the mask corresponding to filled pixels in the image are set
to 1 or to the value specified in MaskFillValue
option as described
below. Additionally, the function fills the border of the mask with ones
to simplify internal processing. It is therefore possible to use the same
mask in multiple calls to the function to make sure the filled areas do
not overlap.newVal
is ignored), and only fills the output mask
with the value
specified in MaskFillValue
as described. This option only make sense in
function variants that have the mask parameter. default falseMask
. This option only make sense in function variants that have the
mask parameter. default 0 (which effectively flood-fills the mask by the
default filling value of 1)The function cv.floodFill fills a connected component starting from the seed point with the specified color. 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 grayscale image and floating range:
src(x',y') - LoDiff <= src(x,y) <= src(x',y') + UpDiff
in case of a grayscale image and fixed range:
src(seed.x,seed.y) - LoDiff <= src(x,y) <= src(seed.x,seed.y) + UpDiff
in case of a color image and floating range: (a conjuction over all channels of the same condition as before)
src(x',y',1) - LoDiff(1) <= src(x,y,1) <= src(x',y',1) + UpDiff(1), and
src(x',y',2) - LoDiff(2) <= src(x,y,2) <= src(x',y',2) + UpDiff(2), and
src(x',y',3) - LoDiff(3) <= src(x,y,3) <= src(x',y',3) + UpDiff(3)
in case of a color image and fixed range: (a conjuction over all channels of the same condition as before)
src(seed.x,seed.y,1) - LoDiff(1) <= src(x,y,1) <= src(seed.x,seed.y,1) + UpDiff(1),
src(seed.x,seed.y,2) - LoDiff(2) <= src(x,y,2) <= src(seed.x,seed.y,2) + UpDiff(2),
src(seed.x,seed.y,3) - LoDiff(3) <= src(x,y,3) <= src(seed.x,seed.y,3) + UpDiff(3)
where src(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:
Use this function to either mark a connected component with the specified color, or build a mask and then extract the contour, or copy the region to another image, and so on.
Note: Since the mask is larger than the filled image, a pixel (x,y)
in
image corresponds to the pixel (x+1,y+1)
in the mask.