Beispiel #1
0
 public void Niblack(LocalBinarizationMethods method)
 {
     using var src = Image("mandrill.png", ImreadModes.Grayscale);
     using var dst = new Mat();
     CvXImgProc.NiblackThreshold(src, dst, 255, ThresholdTypes.Binary, 5, 0.5, method);
     ShowImagesWhenDebugMode(dst);
 }
Beispiel #2
0
        public override void RunTest()
        {
            using var src     = Cv2.ImRead(ImagePath.Binarization, ImreadModes.Grayscale);
            using var niblack = new Mat();
            using var sauvola = 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();
            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("Nick", nick, WindowFlags.AutoSize))
                        {
                            Cv2.WaitKey();
                        }
        }
Beispiel #3
0
        public void Run()
        {
            using var src     = Cv2.ImRead(@"G:\其他项目\YuZe.ColoredPencil\YuZe.ColoredPencil\P10424-172645.jpg", 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();
            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.Normal))
                using (new Window("Niblack", niblack, WindowFlags.Normal))
                    using (new Window("Sauvola", sauvola, WindowFlags.Normal))
                        using (new Window("Nick", nick, WindowFlags.Normal))
                        {
                            Cv2.WaitKey();
                        }
        }
 public void Niblack()
 {
     using (var src = Image("lenna.png", ImreadModes.GrayScale))
         using (var dst = new Mat())
         {
             CvXImgProc.NiblackThreshold(src, dst, 255, ThresholdTypes.Binary, 5, 0.5);
             ShowImagesWhenDebugMode(dst);
         }
 }
Beispiel #5
0
 public void Sauvola()
 {
     foreach (var r in new double[] { 16, 32, 64, 128 })
     {
         using var src = Image("mandrill.png", ImreadModes.Grayscale);
         using var dst = new Mat();
         CvXImgProc.NiblackThreshold(
             src, dst,
             255,
             ThresholdTypes.Binary,
             5, 0.5,
             LocalBinarizationMethods.Sauvola,
             r);
         ShowImagesWhenDebugMode(new[] { dst }, new[] { $"r={r}" });
     }
 }
        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", 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();
                            }
        }