from performing another operation, I get an B/W ( binary ) image which has white and black areas. Now I want to find and floodfill the blacj areas that are completely surrounded by white and not touching the Image border.
The "brute-force" approach i used, which is basically iterating over all pixels( all but the "border" rows/cols), if it finds a black one, I look at the neighbours ( mark them as "visited" ) and if they are black recursively go to their neighbours. And if I only hit white pixels and don't end up at a border I floodfill the area. This can take a while on a high resolution image.
Is there a not too complicated faster way to to this? Thank you.
答案 0 :(得分:0)
As you have a binary image, you can perform a connected component labeling of the black components. All the components found are surrounded with white. Then you go along the borders in order to find the components that touch the border, and you delete them.
An other simpler and faster solution, would be to go along the borders, and as soon as you find a black pixel, you set a seed that expands until all the black pixels that touch the original pixel are white. Doing that, you delete all the black pixels touching the borders. It will remain only the black components that do not touch the borders.
答案 1 :(得分:0)
如果大多数黑色区域没有触及边界,则反向操作可能更快(但同样复杂)。
从边框标记任何可到达的像素(可达到意味着您只能通过黑色像素到达边框)。在此之后完成整个图像的传递。黑色和未访问的任何东西都将是一个被包围的区域。