I think I should use floodFill
, but I don't know how exactly.
Note that the problem is with this specific variation of imfill
, with these parameters.
CodePudding user response:
MATLAB
According to MATLAB's documentation:
BW
is the binary image (black & white image)locations
are pixel coordinates where the operation has to be initiatedconn
the type of connectivity; how the neighboring pixels need to be filled. more details here
OpenCV
OpenCV's floodfill()
has those parameters and a few more. Check this page for details
There are 4 parameters that are must be passed:
image
: this can be 1 or 3-channel image (similar toBW
in MATLAB)mask
: 1-channel image that must be 2 pixels larger in height and width thanimage
seedPoint
: the point where the flood fill operation must start (similar tolocations
in MATLAB)newVal
: the new pixel value to be assigned to locations including and surrounding theseedPoint
.
The optional parameter flags
allows you to choose the connectivity (similar to conn
in MATLAB). The good thing about flags
is that you can come up with combinations. A few examples:
flags = 4
-> flood operation with 4-way connectivityflags = 8
-> flood operation with 8-way connectivityflags = 4 | (255 << 8)
-> flood operation with 4-way connectivity and fill the mask with value 255
There are additional options that can be used see here
CodePudding user response:
Managed to find a solution, the general form of it is as follows:
for an image Mat im
, and vector of locations vector<Point> vec
and using the default of connectivity = 4:
for (int i = 0; i < vec.size(); i )
{
floodFill(im, vec[i], Scalar(255, 255, 255));
}