填充OpenCV中的洞 [英] Fill the holes in OpenCV

查看:1214
本文介绍了填充OpenCV中的洞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 OpenCV (canny edge detection)中的边缘检测模块提取的边缘图。我想做的是填补边缘地图中的洞。

I have an edge map extracted from edge detection module in OpenCV (canny edge detection). What I want to do is to fill the holes in the edge map.

我使用的是 C ++ OpenCV 库。在OpenCV中有一个 cvFloodFill()函数,它将填充空洞种子(有一个位置开始泛滥)。然而,我试图填充所有的内部洞,而不知道种子(类似于 imfill() in MATLAB)

I am using C++, and OpenCV libraries. In OpenCV there is a cvFloodFill() function, and it will fill the holes with a seed (with one of the location to start flooding). However, I am trying to fill all the interior holes without knowing the seeds.(similar to imfill() in MATLAB)

Q1:如何找到所有种子,以便我可以应用cvFloodFill
Q2:如何实现一个'imfill()'等价?

Q1: how to find all the seeds, so that I could apply 'cvFloodFill()'?
Q2: how to implement a 'imfill()' equivalent?

OpenCV中的新手, / p>

Newbie in OpenCV, and any hint is appreciated.

推荐答案

根据 imfill 在MATLAB中:

According to the documentation of imfill in MATLAB:

BW2 = imfill(BW,'holes');
%# fills holes in the binary image BW. A hole is a set
%# of background pixels that cannot be reached by filling in the background
%# from the edge of the image.

因此要获取hole像素,请调用 cvFloodFill 将图片的左角像素作为种子。

Therefore to get the "holes" pixels, make a call to cvFloodFill with the left corner pixel of the image as a seed. You get the holes by complementing the image obtained in the previous step.

BW = im2bw( imread('coins.png') );
subplot(121), imshow(BW)

%# used here as if it was cvFloodFill
holes = imfill(BW, [1 1]);       %# [1 1] is the starting location point

BW(~holes) = 1;                  %# fill holes
subplot(122), imshow(BW)

这篇关于填充OpenCV中的洞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆