Package 

Class Binarize


  • 
    public class Binarize
    
                        

    Image binarization methods.

    • Method Detail

      • otsuAdaptiveThreshold

         static Pix otsuAdaptiveThreshold(Pix pixs)

        Performs locally-adaptive Otsu threshold binarization with defaultparameters.

        Parameters:
        pixs - An 8 bpp PIX source image.
      • otsuAdaptiveThreshold

         static Pix otsuAdaptiveThreshold(Pix pixs, int sizeX, int sizeY, int smoothX, int smoothY, @FloatRange(from = 0.0, to = 1.0) float scoreFraction)

        Performs locally-adaptive Otsu threshold binarization.

        Notes:

        • The Otsu method finds a single global threshold for an image. Thisfunction allows a locally adapted threshold to be found for each tileinto which the image is broken up.
        • The array of threshold values, one for each tile, constitutes ahighly downscaled image. This array is optionally smoothed using aconvolution. The full width and height of the convolution kernel are (2 *smoothX + 1) and (2 * smoothY + 1).
        • The minimum tile dimension allowed is 16. If such small tiles areused, it is recommended to use smoothing, because without smoothing, eachsmall tile determines the splitting threshold independently. A tile thatis entirely in the image bg will then hallucinate fg, resulting in a verynoisy binarization. The smoothing should be large enough that no tile isonly influenced by one type (fg or bg) of pixels, because it will force asplit of its pixels.
        • To get a single global threshold for the entire image, use inputvalues of sizeX and sizeY that are larger than the image. For thissituation, the smoothing parameters are ignored.
        • The threshold values partition the image pixels into two classes: onewhose values are less than the threshold and another whose values aregreater than or equal to the threshold. This is the same use of'threshold' as in pixThresholdToBinary().
        • The scorefract is the fraction of the maximum Otsu score, which isused to determine the range over which the histogram minimum is searched.See numaSplitDistribution() for details on the underlying method ofchoosing a threshold.
        • This uses enables a modified version of the Otsu criterion forsplitting the distribution of pixels in each tile into a fg and bg part.The modification consists of searching for a minimum in the histogramover a range of pixel values where the Otsu score is within a definedfraction, scoreFraction, of the max score. To get the original Otsualgorithm, set scoreFraction == 0.
        Parameters:
        pixs - An 8 bpp PIX source image.
        sizeX - Desired tile X dimension; actual size may vary.
        sizeY - Desired tile Y dimension; actual size may vary.
        smoothX - Half-width of convolution kernel applied to thresholdarray: use 0 for no smoothing.
        smoothY - Half-height of convolution kernel applied to thresholdarray: use 0 for no smoothing.
        scoreFraction - Fraction of the max Otsu score; typ.
      • sauvolaBinarizeTiled

         static Pix sauvolaBinarizeTiled(Pix pixs)

        Performs Sauvola binarization using default values.

        Parameters:
        pixs - An 8 bpp PIX source image.
      • sauvolaBinarizeTiled

         static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, @FloatRange(from = 0.0) float factor, int nx, int ny)

        Performs Sauvola binarization.

        Notes:

        • The window width and height are 2 * whsize + 1. The minimumvalue for whsize is 2; typically it is >= 7.
        • For nx == ny == 1, this defaults to pixSauvolaBinarize().
        • Why a tiled version?(a) Because the mean value accumulator is a uint32, overflowcan occur for an image with more than 16M pixels.(b) The mean value accumulator array for 16M pixels is 64 MB.The mean square accumulator array for 16M pixels is 128 MB.Using tiles reduces the size of these arrays.(c) Each tile can be processed independently, in parallel,on a multicore processor.
        • The Sauvola threshold is determined from the formula:t = m * (1 - k * (1 - s / 128))where:t = local thresholdm = local meank = @factor (>= 0) [ typ. 0.35 ]s = local standard deviation, which is maximized at127.5 when half the samples are 0 and half are 255.
        • The basic idea of Niblack and Sauvola binarization is thatthe local threshold should be less than the median value, and the largerthe variance, the closer to the median it should be chosen. Typicalvalues for k are between 0.2 and 0.5.
        Parameters:
        pixs - An 8 bpp PIX source image.
        whsize - Window half-width for measuring local statistics
        factor - Factor for reducing threshold due to variance; >= 0
        nx - Subdivision into tiles; >= 1
        ny - Subdivision into tiles; >= 1