图像边界的提取
图像边界的提取相对于图像轮廓的跟踪来说,实现起来比较简单。但是我继承了图像轮廓跟踪的类。我们来先看下面一张图,以便对边界提取有一个形象的了解。
前半部分是图像原图,后一半部分是提取边界后的图行。它的具体实现代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private void Bound_Click(object sender, EventArgs e)
{
if (bitMap != null)
{
BoundExtract boundExtract = new BoundExtract(bitMap);
boundExtract.Draw();
Invalidate();
}
}
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class BoundExtract:ImageFeature
2 {
3 bool bBound; //是否是边界点的判断
4
5 public BoundExtract(Bitmap bitmap):base(bitmap)
6 {
7 }
8
9 /// <summary>
10 ///3X3的边界提取
11 /// </summary>
12 public void Extract()
13 {
14 for(int j=1;j<h-1;j++)
15 for (int i = 1; i < w - 1; i++)
16 {
17 bBound = false;
18 if (binary[i, j] == 0) continue;
19 for(int k=-1;k<=1;k++)
20 for (int l = -1; l <= 1; l++)
21 {
22 if (binary[i + k, j + l] == 0)
23 {
24 bBound = true;
25 k = 2;
26 l = 2;
27 }
28 }
29 if (!bBound) bitMap.SetPixel(i, j, Color.FromArgb(255, 255, 255)); //不是边界点将其置为白色
30 }
31 }
32
33 public override void Draw()
34 {
35 ToBianry();
36 Extract();
37 }
38 }