Beispiel #1
0
        public static Mat <byte> Blur(Mat <byte> image, double sigma = 1.0)
        {
            Mat <double> tmp = ImgProc.Convolve2D(image, GetGaussianKernel(sigma));

            Mat <byte> result = new Mat <byte>(tmp.Size);

            for (int i = 0; i < result.Rows; i++)
            {
                for (int j = 0; j < result.Cols; j++)
                {
                    result[i, j] = (byte)tmp[i, j];
                }
            }

            return(result);
        }
Beispiel #2
0
        public static Tuple <Mat <double>, Mat <double> > GetGradient(Mat <byte> image, double sigma = 1.0)
        {
            Tuple <Mat <double>, Mat <double> > kernel = GetGradientKernel(sigma);
            Mat <double> dxImage = ImgProc.Convolve2D(image, kernel.Item1);
            Mat <double> dyImage = ImgProc.Convolve2D(image, kernel.Item2);

            Mat <double> orientImage = new Mat <double>(image.Size);

            for (int i = 0; i < image.Rows; i++)
            {
                for (int j = 0; j < image.Cols; j++)
                {
                    double orient = Math.Atan2(dyImage[i, j], dxImage[i, j]);
                    while (orient >= Math.PI)
                    {
                        orient -= Math.PI;
                    }
                    while (orient < 0)
                    {
                        orient += Math.PI;
                    }

                    orientImage[i, j] = orient;
                }
            }

            Mat <double> powerImage = new Mat <double>(image.Size);

            for (int i = 0; i < image.Rows; i++)
            {
                for (int j = 0; j < image.Cols; j++)
                {
                    powerImage[i, j] = Math.Sqrt(
                        dyImage[i, j] * dyImage[i, j] + dxImage[i, j] * dxImage[i, j]);
                }
            }

            return(Tuple.Create(powerImage, orientImage));
        }