Win8 Metro(C#)数字图像处理--2.74图像凸包计算

Win8 Metro(C#)数字图像处理--2.74图像凸包计算_第1张图片

        /// <summary>
        /// Convex Hull compute.
        /// </summary>
        /// <param name="points">The source image points.</param>
        /// <param name="startPoints"></param>
        /// <param name="endPoints"></param>
        private static void ConvexhullCompute(ref Point[] srcPoints,ref List<Point>startPoints,  ref List<Point> endPoints)
        {
            Point start;
            Point end;
            double a = 0, b = 0;
            int signa = 0, signb = 0;
            int max = srcPoints.Length;
            double temp = 0.0;
            int t = 0;
            double tx = 0.0;
            for (int i = 0; i < max; i++)
            {
                start = srcPoints[i];
                for (int k = i + 1; k < max; k++)
                {
                    end = srcPoints[k];
                    if (start.X == end.X)
                    {
                        for (int j = 0; j < max; j++)
                        {
                            if ((!(signa > 0 && signb > 0)) && (j != i && j != k))
                            {
                                t = srcPoints[j].X;
                                if (t > start.X)
                                    signa++;
                                if (t < start.X)
                                    signb++;
                            }
                        }
                    }
                    else
                    {
                        a = (double)(end.Y - start.Y) / (double)(end.X - start.X);
                        b = (double)start.Y - (double)start.X * a;
                        for (int j = 0; j < max; j++)
                        {
                            if ((!(signa > 0 && signb > 0)) && (j != i && j != k))
                            {
                                temp = a * (double)srcPoints[j].X + b;
                                tx = (double)srcPoints[j].Y;
                                if (temp > tx)
                                    signa++;
                                if (temp < tx)
                                    signb++;
                            }
                        }
                    }
                    if (signa * signb == 0)
                    {
                        startPoints.Add(start);
                        endPoints.Add(end);
                    }
                    signb = 0;
                    signa = 0;
                }
            }
        }

Win8 Metro(C#)数字图像处理--2.74图像凸包计算_第2张图片

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:
http://www.zealpixel.com/portal.php

你可能感兴趣的:(Win8 Metro(C#)数字图像处理--2.74图像凸包计算)