cv2.floodFill(整理中,未完成)

opencv_python 4.5.1

◆ floodFill() 

Python:
 retval, image, mask, rect=cv.floodFill(image, mask, seedPoint, newVal[, loDiff[, upDiff[, flags]]])

#include <opencv2/imgproc.hpp>

Fills a connected component with the given color.

用指定颜色填充图像的某块区域。

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:

floodFill函数用指定颜色,从指定的种子像素点(seed point)开始填充连通的区域。是否连通,取决于相邻像素的颜色/亮度的接近程度。像素点(x,y)是否被视为需要填充的区域,判断条件如下:

  • 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

    and

     

    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

    and

     

    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:

其中,src(x′,y′)是已知属于像素点(x,y)连通区域的相邻像素。

  • 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.

Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on.

Parameters

imageInput/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See the details below.
maskOperation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than image. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags 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.
seedPointStarting point.
newValNew value of the repainted domain pixels.
loDiffMaximal 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.
upDiffMaximal 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.
rectOptional output parameter set by the function to the minimum bounding rectangle of the repainted domain.
flagsOperation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the mask (the default value is 1). For example, 4 | ( 255 << 8 ) will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (|), see FloodFillFlags.

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 .

See also

findContours

 

 

参考:

[1] openCV官方文档:https://docs.opencv.org/4.5.1/d7/d1b/group__imgproc__misc.html#gaf1f55a048f8a45bc3383586e80b1f0d0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuki_chan_0502

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值