Esempio n. 1
0
        public IplImage BinarizerMethod(IplImage src)
        {
            bina = new IplImage(src.Size, BitDepth.U8, 1);
            gray = this.GrayScale(src);

            Binarizer.Bernsen(gray, bina, 52, 60, 150);

            return(bina);
        }
Esempio n. 2
0
        public BinarizationMethods()
        {
            const int Size = 61;

            using (var imgSrc = new IplImage(FilePath.Image.Binarization, LoadMode.GrayScale))
                using (var imgGauss = imgSrc.Clone())
                    using (var imgNiblack = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                        using (var imgSauvola = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                            using (var imgBernsen = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                                using (var imgNick = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                                {
                                    //Cv.Smooth(imgSrc, imgGauss, SmoothType.Gaussian, 9);
                                    //Cv.EqualizeHist(imgGauss, imgGauss);

                                    Stopwatch sw = Stopwatch.StartNew();
                                    {
                                        const double K = -0.2;
                                        Binarizer.NiblackFast(imgGauss, imgNiblack, Size, K);
                                    }
                                    Console.WriteLine("Niblack: {0}ms", sw.ElapsedMilliseconds);
                                    sw.Reset(); sw.Start();
                                    {
                                        const double K = 0.2;
                                        const double R = 64;
                                        Binarizer.SauvolaFast(imgGauss, imgSauvola, Size, K, R);
                                    }
                                    Console.WriteLine("Sauvola: {0}ms", sw.ElapsedMilliseconds);
                                    sw.Reset(); sw.Start();
                                    {
                                        const byte ContrastMin = 15;
                                        const byte BgThreshold = 127;
                                        Binarizer.Bernsen(imgGauss, imgBernsen, Size, ContrastMin, BgThreshold);
                                    }
                                    Console.WriteLine("bernsen: {0}ms", sw.ElapsedMilliseconds);
                                    sw.Reset(); sw.Start();
                                    {
                                        const double K = -0.14;
                                        Binarizer.Nick(imgGauss, imgNick, Size, K);
                                    }
                                    Console.WriteLine("nick: {0}ms", sw.ElapsedMilliseconds);

                                    using (new CvWindow("src", imgSrc))
                                        //using (new CvWindow("gauss", imgGauss))
                                        using (new CvWindow("niblack", imgNiblack))
                                            using (new CvWindow("sauvola", imgSauvola))
                                                using (new CvWindow("bernsen", imgBernsen))
                                                    using (new CvWindow("nick", imgNick))
                                                    {
                                                        Cv.WaitKey();
                                                    }
                                }
        }
Esempio n. 3
0
        public void Run()
        {
            using (var src = Cv2.ImRead(FilePath.Image.Binarization, ImreadModes.GrayScale))
                using (var niblack = new Mat())
                    using (var sauvola = new Mat())
                        using (var bernsen = new Mat())
                            using (var nick = new Mat())
                            {
                                int kernelSize = 51;

                                var sw = new Stopwatch();
                                sw.Start();
                                Binarizer.Niblack(src, niblack, kernelSize, -0.2);
                                sw.Stop();
                                Console.WriteLine($"Niblack {sw.ElapsedMilliseconds} ms");

                                sw.Restart();
                                Binarizer.Sauvola(src, sauvola, kernelSize, 0.1, 64);
                                sw.Stop();
                                Console.WriteLine($"Sauvola {sw.ElapsedMilliseconds} ms");

                                sw.Restart();
                                Binarizer.Bernsen(src, bernsen, kernelSize, 50, 200);
                                sw.Stop();
                                Console.WriteLine($"Bernsen {sw.ElapsedMilliseconds} ms");

                                sw.Restart();
                                Binarizer.Nick(src, nick, kernelSize, -0.14);
                                sw.Stop();
                                Console.WriteLine($"Nick {sw.ElapsedMilliseconds} ms");

                                using (new Window("src", WindowMode.AutoSize, src))
                                    using (new Window("Niblack", WindowMode.AutoSize, niblack))
                                        using (new Window("Sauvola", WindowMode.AutoSize, sauvola))
                                            using (new Window("Bernsen", WindowMode.AutoSize, bernsen))
                                                using (new Window("Nick", WindowMode.AutoSize, nick))
                                                {
                                                    Cv2.WaitKey();
                                                }
                            }
        }
Esempio n. 4
0
        public void Run()
        {
            using var src     = Cv2.ImRead(FilePath.Image.Binarization, ImreadModes.Grayscale);
            using var niblack = new Mat();
            using var sauvola = new Mat();
            using var bernsen = new Mat();
            using var nick    = new Mat();
            int kernelSize = 51;

            var sw = new Stopwatch();

            sw.Start();
            CvXImgProc.NiblackThreshold(src, niblack, 255, ThresholdTypes.Binary, kernelSize, -0.2, LocalBinarizationMethods.Niblack);
            sw.Stop();
            Console.WriteLine($"Niblack {sw.ElapsedMilliseconds} ms");

            sw.Restart();
            CvXImgProc.NiblackThreshold(src, sauvola, 255, ThresholdTypes.Binary, kernelSize, 0.1, LocalBinarizationMethods.Sauvola);
            sw.Stop();
            Console.WriteLine($"Sauvola {sw.ElapsedMilliseconds} ms");

            sw.Restart();
            Binarizer.Bernsen(src, bernsen, kernelSize, 50, 200);
            sw.Stop();
            Console.WriteLine($"Bernsen {sw.ElapsedMilliseconds} ms");

            sw.Restart();
            CvXImgProc.NiblackThreshold(src, nick, 255, ThresholdTypes.Binary, kernelSize, -0.14, LocalBinarizationMethods.Nick);
            sw.Stop();
            Console.WriteLine($"Nick {sw.ElapsedMilliseconds} ms");

            using (new Window("src", src, WindowFlags.AutoSize))
                using (new Window("Niblack", niblack, WindowFlags.AutoSize))
                    using (new Window("Sauvola", sauvola, WindowFlags.AutoSize))
                        using (new Window("Bernsen", bernsen, WindowFlags.AutoSize))
                            using (new Window("Nick", nick, WindowFlags.AutoSize))
                            {
                                Cv2.WaitKey();
                            }
        }