public void BinaryDilation3x3Test1()
        {
            string basePath = NUnit.Framework.TestContext.CurrentContext.TestDirectory;

            #region doc_binary_dilation_3x3
            // Let's start with one of the default
            // color test images in the framework:
            var test = new TestImages(basePath);

            // Let's get Lena's picture
            Bitmap bmp = test["lena.bmp"];

            // And transform it to a binary mask
            // using Niblack's threshold class
            var    niblack = new NiblackThreshold();
            Bitmap binary  = niblack.Apply(bmp);

            // The result can be seen below:
            // ImageBox.Show(binary);

            // Now, let's finally apply the dilation
            // filter to the binarized image below:
            var    dil3x3 = new BinaryDilation3x3();
            Bitmap result = dil3x3.Apply(binary);

            // The result can be seen below:
            // ImageBox.Show(result);
            #endregion

            //result.Save(@"C:\Projects\morpho-dilation3x3-result.png");
            //binary.Save(@"C:\Projects\morpho-dilation3x3-binary.png");
        }
Exemplo n.º 2
0
        public void NiblackTest2()
        {
            double[,] diag = Matrix.Magic(5);

            Bitmap input;

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

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

            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[, ]
            {
                { 0, 0, 1, 1, 0 },
                { 0, 1, 1, 0, 0 },
                { 1, 1, 0, 0, 0 },
                { 1, 0, 0, 0, 1 },
                { 1, 0, 0, 1, 1 }
            };

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

            System.Drawing.Bitmap gray    = Grayscale.CommonAlgorithms.RMY.Apply(canvasTool.getBitmapFromCanvas());
            System.Drawing.Bitmap resault = niblack.Apply(gray);
            canvasTool.SetBmpImageToCanvas(resault);
        }
Exemplo n.º 4
0
        private void NiblackTransforms_Click(object sender, EventArgs e)
        {
            Bitmap           img     = new Bitmap(openSourceDialog.FileName);
            NiblackThreshold niblack = new NiblackThreshold();

            //niblack.Radius = Int32.Parse(paramsTextBox.Text);
            niblack.K = -0.2;
            resultPictureBox.Image = niblack.Apply(img);
        }
Exemplo n.º 5
0
        private async Task NiblackBinaryzation(int size = 25, double k = 0.5)
        {
            AddToUndo(WriteableOutputImage.Clone());
            ConvertToGrayScalePageMenuFlyoutItem_Click(null, null);

            NiblackThreshold niblack = new NiblackThreshold(size, k);

            WriteableOutputImage = niblack.Threshold(WriteableOutputImage);

            await UpdateOutputImage();
        }
Exemplo n.º 6
0
        public void NiblackTest1()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Resources.lena512);

            NiblackThreshold niblack = new NiblackThreshold();

            Bitmap result = niblack.Apply(image);

            // ImageBox.Show(result);

            Assert.IsNotNull(result);
        }
Exemplo n.º 7
0
        public void NiblackTest1()
        {
            Bitmap image = Properties.Resources.lena512;

            NiblackThreshold niblack = new NiblackThreshold();

            Bitmap result = niblack.Apply(image);

            // ImageBox.Show(result);

            Assert.IsNotNull(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Binarize image with Niblack 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 NiblackBinarization(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 NiblackThreshold()
            {
                K = k, Radius = radius
            };

            return(threshold.Apply(image));
        }
Exemplo n.º 9
0
        public static Bitmap MorphologyNiblackBinarization(this Bitmap image, double k, int radius, int morphologyKernel, byte globalThreshold)
        {
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new NotSupportedException("Filter can be applied to binary 8bpp images only");
            }
            Erosion morphologyErosion   = new Erosion();
            Bitmap  tempMorphologyImage = morphologyErosion.Apply(image);

            for (int i = 0; i < morphologyKernel - 1; i++)
            {
                tempMorphologyImage = morphologyErosion.Apply(tempMorphologyImage);
            }
            SimpleGrayImage morphologyImage = new SimpleGrayImage(tempMorphologyImage);

            var threshold = new NiblackThreshold()
            {
                K = k, Radius = radius
            };
            SimpleGrayImage localBinImage = new SimpleGrayImage(threshold.Apply(image));

            for (int i = 0; i < morphologyImage.Cols; i++)
            {
                for (int j = 0; j < morphologyImage.Rows; j++)
                {
                    if (morphologyImage.Data[j, i] > globalThreshold)
                    {
                        morphologyImage.Data[j, i] = 255;
                    }
                    else
                    {
                        morphologyImage.Data[j, i] = localBinImage.Data[j, i];
                    }
                }
            }
            return(morphologyImage.Bitmap);
        }