在检测物体的轮廓时,我们通常会使用到opencv中的findcontour和drawcontour,比较常用而且效果不错。
1985年,satoshi suzuki发表了一篇论文,Topological structural analysis of digitized binary images by border following,他介绍了两种算法来实现轮廓的提取,当然输入的图像是二值图像。findcontour就是基于这篇论文的思路来实现。
1. 上下左右极限位置构成了frame, 假定frame像素由0 构成
2. 由像素0构成的componet :如果包含frame, 那将其称之为background;若不包含frame,则称为hole;
3. 定义一:
In the 4- (8-) connected case, a 1-pixel (i, j) having a 0-pixel ( p, q) in its 8- (4) neighborhood is called a border point.
It is also described as “a border point between a 1-component S1, and a 0-components S2,”
if (i, j) is a member of S1 and (p, q) is a member of S2.
定义二: (surroundness among connected components).
For given two connected components S1 and S2 in a binary picture, if there exists a pixel belonging to S2 for any 4-path from a pixel in S1 to a pixel on the frame, we say that S2 surrounds S1.
If S2 surrounds S1 and there exists a border point between them, then S2 is said to surround S1 directly.
定义三: (outer border and hole border).
An outer border is defined as the set of the border points between an arbitrary 1-component and the 0-component which surrounds it directly. Similarly, we refer to the set of the border points between a hole and the 1-component which surrounds it directly asa hole border.
We use the term “border” for either an outer border or a hole border. Note that the hole border is defined as a set of 1-pixels (not 0-pixels)as well as the outer border.
定义四:
The parent border of an outer border between a1-component S1 and the 0-component S2 which surrounds S1 directly is defined as:
(1) the hole border between S2 and the 1-component which surrounds S2directly, if S2 is ahole;
(2) the frame of the picture, if S2 is the background.
定义五:
For two given borders B0 and Bn of a binary picture, we say that Bn surrounds B0 is there exists a sequence of border B0, B1, . . . , Bn such that Bk if the parent border of Bk-1, for all k (1 <= k <= n)
论文主要介绍了两种算法,用来对数字二值图像进行拓扑分析。第一种算法是在确定二值图像边界的围绕关系,即确定外边界、孔边界以及他们的层次关系,由于这些边界和原图的区域具有一一对应关系(外边界对应像素值为1的连通区域,孔边界对应像素值为0的区域),因此我们就可以用边界来表示原图。第二种算法,是第一种算法的修改版本,本质一样,但是它只找最外面的边界。
即:一个是确定这些border的包含关系
一个是只找最外层的border
1、每次行扫描,遇到以下两种情况,确定外边界(outer boeder)和孔边界(hole border):
(1)f(i,j-1)=0,f(i,j)=1;//f(i,j)是外边界的起始点
(2)f(i,j)>=1,f(i,j+1)=0;//f(i,j)是孔边界的起始点
2、然后给它编号(编号唯一,由NBD指定)
在这里分配一个唯一的标示符给新发现的边界,叫做NBD。初始时NBD=1,每次发现一个新边界加1。在这个过程中,遇到f(p,q)=1,f(p,q+1)=0时,将f(p,q)置为-NBD。什么意思呢?就是右边边界的终止点。