MATLAB File Help: cv.floodFill | Index |
Fills a connected component with the given color
dst = cv.floodFill(src, seed, newVal)
[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.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(seedPoint.x,seedPoint.y) - loDiff <= src(x,y) <= src(seedPoint.x,seedPoint.y) + upDiff
in case of a color image and floating range:
src(x',y')r - loDiffr <= src(x,y)r <= src(x',y')_r + upDiffr, src(x',y')g - loDiffg <= src(x,y)g <= src(x',y')_g + upDiffg src(x',y')b - loDiffb <= src(x,y)b <= src(x',y')_b + upDiffb
in case of a color image and fixed range:
src(seedPoint.x,seedPoint.y)r - loDiffr <= src(x,y)r <= src(seedPoint.x,seedPoint.y)_r + upDiffr, src(seedPoint.x,seedPoint.y)g - loDiffg <= src(x,y)g <= src(seedPoint.x,seedPoint.y)_g + upDiffg src(seedPoint.x,seedPoint.y)b - loDiffb <= src(x,y)b <= src(seedPoint.x,seedPoint.y)_b + upDiffb
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.