コード例 #1
0
ファイル: SauvolaTest.cs プロジェクト: xadxxadx/framework
        public void SauvolaTest2()
        {
            double[,] diag = Matrix.Magic(5);

            Bitmap input;

            new MatrixToImage().Convert(diag, out input);

            // Create a new Variance filter
            SauvolaThreshold filter = new SauvolaThreshold();

            Assert.AreEqual(PixelFormat.Format8bppIndexed, input.PixelFormat);

            // Apply the filter
            Bitmap output = filter.Apply(input);

            double[,] actual;

            new ImageToMatrix().Convert(output, out actual);

            Assert.AreEqual(PixelFormat.Format8bppIndexed, output.PixelFormat);

            string str = actual.ToString(CSharpMatrixFormatProvider.InvariantCulture);

            double[,] expected = new double[, ]
            {
                { 1, 1, 1, 1, 1 },
                { 1, 1, 1, 1, 1 },
                { 1, 1, 1, 1, 1 },
                { 1, 1, 1, 1, 1 },
                { 1, 1, 1, 1, 1 }
            };

            Assert.IsTrue(expected.IsEqual(actual, 1e-6));
        }
        private void SauvolaThreshold_Click(object sender, RoutedEventArgs e)
        {
            var sauvola = new SauvolaThreshold();

            System.Drawing.Bitmap gray    = Grayscale.CommonAlgorithms.RMY.Apply(canvasTool.getBitmapFromCanvas());
            System.Drawing.Bitmap resault = sauvola.Apply(gray);
            canvasTool.SetBmpImageToCanvas(resault);
        }
コード例 #3
0
ファイル: SauvolaTest.cs プロジェクト: xadxxadx/framework
        public void SauvolaTest1()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Properties.Resources.lena512);

            SauvolaThreshold sauvola = new SauvolaThreshold();

            Bitmap result = sauvola.Apply(image);

            // ImageBox.Show(result);

            Assert.IsNotNull(result);
        }
コード例 #4
0
        /// <summary>
        /// Binarize image with Sauvola filter
        /// </summary>
        /// <param name="image"></param>
        /// <param name="k"></param>
        /// <param name="radius">radius of local area of pixel </param>
        /// <returns></returns>
        public static Bitmap SauvolaBinarization(this Bitmap image, double k, int radius)
        {
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new NotSupportedException("Filter can be applied to binary 8bpp images only");
            }
            var threshold = new SauvolaThreshold()
            {
                K = k, Radius = radius
            };

            return(threshold.Apply(image));
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: kineva1992/repos
        private void binarToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Bitmap img = new Bitmap(pictureBox1.Image);

            SauvolaThreshold sav = new SauvolaThreshold();

            Bitmap result = sav.Apply(img);


            pictureBox2.Image = result;


            //pictureBox2.Image = result.Apply((Bitmap)pictureBox1.Image);
        }
コード例 #6
0
ファイル: SauvolaTest.cs プロジェクト: xadxxadx/framework
        public void SauvolaTest3()
        {
            double[,] diag = Matrix.Magic(5);

            Bitmap input;

            new MatrixToImage()
            {
                Format = PixelFormat.Format32bppRgb,
            }.Convert(diag, out input);

            Assert.AreEqual(PixelFormat.Format32bppRgb, input.PixelFormat);

            SauvolaThreshold filter = new SauvolaThreshold();

            // Apply the filter
            Bitmap output = filter.Apply(input);

            Assert.AreEqual(PixelFormat.Format32bppRgb, output.PixelFormat);

            double[,] actual;

            for (int i = 0; i < 3; i++)
            {
                new ImageToMatrix()
                {
                    Channel = i
                }.Convert(output, out actual);

                string str = actual.ToString(CSharpMatrixFormatProvider.InvariantCulture);

                double[,] expected = new double[, ]
                {
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1 }
                };

                Assert.IsTrue(expected.IsEqual(actual, 1e-6));
            }
        }