[原]imfill 的openCV实现

标签:
it |
分类: 图像处理/openCV |
其实主要是imfill(matrix,
'holes'); 的openCV/C++ 实现。
Overview:
imfill是matlab的一个函数,在http://www.mathworks.cn/cn/help/images/ref/imfill.html
中有详细的讲解。这个函数有好几种不同的签名。在这里我的侧重点是imfill(m,
'holes'),以及如何用openCV来实现imfill一样的功能。本文有三部分组成。
1. 使用Matlab 的imfill
进行填充图像
在Matlab中简单的几行代码就能实现:
1
2 3 4 5 6 7 8 |
clc;
clear; BW imshow(BW); holes BW(~holes) figure,imshow(holes); |
左图为填充前的图像,右图是填充后的图像:
http://s1/mw690/79bb01d0td71c1b8a7590&690的openCV实现" TITLE="[原]imfill 的openCV实现" />
C++ Code
http://s5/bmiddle/79bb01d0td71c1c0fa824&690的openCV实现" TITLE="[原]imfill 的openCV实现" />
2.
用opencv来实现imfill(bw, 'holes')
opencv
在这里不像matlab那么好用了,matlab调用下。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include
#include #include using using void { } void { } void { } |
3. imfill
和opencv实现的imfill 对矩阵进行操作的对比
我仍有点不放心,觉得尽管2幅图看起来差不多,但是是不是完全一样呢,然后我觉得用个矩阵试一下。
m = [1, 1, 1, 0, 0, 0,
0, 0;
without_holes =
imfill(m, 'holes')
得到结果:
without_holes =
1
1
1
0
0
0
0
0
1
1
1
0
1
1
0
0
1
1
1
0
1
1
0
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
0
1
1
0
1
1
1
0