Niblack Threshold.

The Niblack filter is a local thresholding algorithm that separates white and black pixels given the local mean and standard deviation for the current window.

This filter implementation has been contributed by Diego Catalano.

References: W. Niblack, An Introduction to Digital Image Processing, pp. 115-116. Prentice Hall, 1986.

Inheritance: BaseFilter
Ejemplo n.º 1
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();

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

            double[,] actual;

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

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

            double[,] expected = 
            {
                { 0, 0, 0, 0, 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));
        }
Ejemplo n.º 2
0
        private void SetFilter()
        {
            ImageType = ImageTypes.Rgb24bpp;
            Af.NiblackThreshold newFilter = new Af.NiblackThreshold();
            newFilter.K      = k;
            newFilter.C      = Remap(c, 0, 255);
            newFilter.Radius = radius;

            imageFilter = newFilter;
        }
Ejemplo n.º 3
0
        public void NiblackTest1()
        {
            Bitmap image = Properties.Resources.lena512;

            NiblackThreshold niblack = new NiblackThreshold();

            Bitmap result = niblack.Apply(image);

            // ImageBox.Show(result);

            Assert.IsNotNull(result);
        }
Ejemplo n.º 4
0
        public void NiblackTest3()
        {
            double[,] diag = Matrix.Magic(5);

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

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

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

            // 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[,] 
                {
                    { 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));
            }
        }