当前位置:编程学习 > C#/ASP.NET >>

C#图像细化:Hilditch细化算法

上理论:
Hilditch 细化算法的步骤为:

对图像从左向右从上向下迭代每个像素,是为一个迭代周期。在每个迭代周期中,对于每一个像素p,如果它同时满足6个条件,则标记它。在当前迭代周期结束时,则把所有标记的像素的值设为背景值。如果某次迭代周期中不存在标记点(即满足6个条件的像素),则算法结束。假设背景值为0,前景值为1,则:

6个条件为:

(I):p 为1,即p不是背景;

(2):x1,x3,x5,x7不全部为1(否则把p标记删除,图像空心了);

(3):x1~x8 中,至少有2个为1(若只有1个为1,则是线段的端点。若没有为1的,则为孤立点);

(4):p的8连通联结数为1;

联结数指在像素p的3*3邻域中,和p连接的图形分量的个数:

(5)假设x3已经标记删除,那么当x3为0时,p的8联通联结数为1;

(6)假设x5已经标记删除,那么当x5为0时,p的8联通联结数为1。


我上一个自己写的代码

 

[csharp]
/// <summary>  
        /// Hilditch细化算法  
        /// </summary>  
        /// <param name="input"></param>  
        /// <returns></returns>  
        private int[,] ThinnerHilditch(int[,] input) 
        { 
            int lWidth = input.GetLength(0); 
            int lHeight = input.GetLength(1); 
 
            bool IsModified = true; 
            int Counter = 1; 
            int[] nnb = new int[9]; 
            //去掉边框像素  
            for (int i = 0; i < lWidth; i++) 
            { 
                input[i, 0] = 0; 
                input[i, lHeight - 1] = 0; 
            } 
            for (int j = 0; j < lHeight; j++) 
            { 
                input[0, j] = 0; 
                input[lWidth - 1, j] = 0; 
            } 
            do 
            { 
                Counter++; 
                IsModified = false; 
                int[,] nb = new int[3, 3]; 
                for (int i = 1; i < lWidth; i++) 
                { 
                    for (int j = 1; j < lHeight; j++) 
                    { 
                        //条件1必须为黑点  
                        if (input[i, j] != 1) 
                        { 
                            continue; 
                        } 
 
                        //取3*3领域  
                        for (int m = 0; m < 3; m++) 
                        { 
                            for (int n = 0; n < 3; n++) 
                            { 
                                nb[m, n] = input[i - 1 + m, j - 1 + n]; 
                            } 
                        } 
                        //复制  
                        nnb[0] = nb[2, 1]==1?0:1; 
                        nnb[1] = nb[2, 0]==1?0:1; 
                        nnb[2] = nb[1, 0]==1?0:1; 
                        nnb[3] = nb[0, 0]==1?0:1; 
                        nnb[4] = nb[0, 1]==1?0:1; 
                        nnb[5] = nb[0, 2]==1?0:1; 
                        nnb[6] = nb[1, 2]==1?0:1; 
                 &nbs

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,