コード例 #1
0
        /*
         * // ratio of lower:upper threshold
         * private static int ratio = 3;
         *
         * // maximum value for the lower Threshold
         * private static int max_lowThreshold = 100;
         * private static double[][] Gx =
         *  new[] {
         *      new double[] { -1, 0, +1 },
         *      new double[] { -2, 0, +2 },
         *      new double[] { -1, 0, +1 }
         *  };
         *
         * private static double[][] Gy =
         *  new[] {
         *      new double[] { -1, -2, -1 },
         *      new double[] { +0, +0, +0 },
         *      new double[] { +1, +2, +1 }
         *  };
         */
        /*
         *
         * GAUSSIAN_NOISE_ REDUCE
         *
         * apply 5x5 Gaussian convolution filter, shrinks the image by 4 pixels in each direction, using Gaussian filter found here:
         *
         * http://en.wikipedia.org/wiki/Canny_edge_detector
         *
         */
        private static IImage <double> CannyEdgeDetect(IImage <double> img_in, double highThresholdPercentage, double lowThresholdPercentage)
        {
            double[] g;
            int[]    direction;
            CalcGradientSobel(img_in, out g, out direction);

            IImage <double> img_scratch = ImageFactory.Generate(img_in.Width, img_in.Height);

            CannyEdgeDetector.NonMaxSuppression(img_scratch, g, direction);

            double high, low;

            EstimateThreshold(img_scratch, highThresholdPercentage, lowThresholdPercentage, out high, out low);

            return(hysteresis(high, low, img_scratch));
        }
コード例 #2
0
        public static IImage <double> Run(IImage <double> img, CannyOptions options)
        {
            options = options ?? new CannyOptions();

            var img256 = img.Copy();

            if (options.NormalizeImage)
            {
                img256 = img256.Normalize256();
            }

            // or morph_close
            var img_out = options.NoiseReduce ? CannyEdgeDetector.GaussianNoiseReduce(img256) : img256;

            return(CannyEdgeDetector.CannyEdgeDetect(img_out, options.HighThresholdPercentage, options.LowThresholdPercentage));
        }
コード例 #3
0
        private static IImage <double> hysteresis(double high, double low, IImage <double> img_in)
        {
            IImage <double> img_out = new Image(img_in.Width, img_in.Height);

            for (int y = 0; y < img_out.Height; y++)
            {
                for (int x = 0; x < img_out.Width; x++)
                {
                    if (img_in[y * img_out.Width + x] >= high)
                    {
                        CannyEdgeDetector.Trace(x, y, low, img_in, img_out);
                    }
                }
            }

            return(img_out);
        }
コード例 #4
0
 public static IImage <double> Run(IImage <double> img)
 {
     return(CannyEdgeDetector.Run(img, null));
 }