The Sauvola filter is a variation of the NiblackThreshold thresholding filter.
This filter implementation has been contributed by Diego Catalano.
References: Sauvola, Jaakko, and Matti Pietikäinen. "Adaptive document image binarization." Pattern Recognition 33.2 (2000): 225-236.
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 SetFilter() { ImageType = ImageTypes.Rgb24bpp; Af.SauvolaThreshold newFilter = new Af.SauvolaThreshold(); newFilter.K = k; newFilter.R = Remap(r, 0, 255); newFilter.Radius = radius; imageFilter = newFilter; }
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); }
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)); } }