Class GThresholdImageOps

java.lang.Object
boofcv.alg.filter.binary.GThresholdImageOps

public class GThresholdImageOps
extends Object
Weakly typed version of ThresholdImageOps.
  • Constructor Summary

    Constructors
    Constructor Description
    GThresholdImageOps()  
  • Method Summary

    Modifier and Type Method Description
    static <T extends ImageGray<T>>
    GrayU8
    blockMean​(T input, @Nullable GrayU8 output, ConfigLength width, double scale, boolean down)
    Applies a threshold to an image by computing the mean values in a regular grid across the input image.
    static <T extends ImageGray<T>>
    GrayU8
    blockMinMax​(T input, @Nullable GrayU8 output, ConfigLength width, double scale, boolean down, double textureThreshold)
    Applies a threshold to an image by computing the min and max values in a regular grid across the input image.
    static <T extends ImageGray<T>>
    GrayU8
    blockOtsu​(T input, @Nullable GrayU8 output, boolean otsu2, ConfigLength width, double tuning, double scale, boolean down)
    Applies a threshold to an image by computing the Otsu threshold in a regular grid across the input image.
    static int computeEntropy​(int[] histogram, int length, int totalPixels)
    Computes a threshold which maximizes the entropy between the foreground and background regions.
    static double computeEntropy​(ImageGray input, double minValue, double maxValue)
    Computes a threshold which maximizes the entropy between the foreground and background regions.
    static int computeHuang​(int[] histogram, int length)
    Implements Huang's fuzzy thresholding method Uses Shannon's entropy function (one can also use Yager's entropy function) Huang L.-K.
    static double computeHuang​(ImageGray input, double minValue, double maxValue)
    Computes Huang's Minimum fyzzy thresholding from an input image.
    static int computeLi​(int[] histogram, int length)
    Implements Li's Minimum Cross Entropy thresholding method This implementation is based on the iterative version (Ref.
    static double computeLi​(ImageGray input, double minValue, double maxValue)
    Computes Li's Minimum Cross Entropy thresholding from an input image.
    static int computeOtsu​(int[] histogram, int length, int totalPixels)
    Computes the variance based Otsu threshold from a histogram directly.
    static double computeOtsu​(ImageGray input, double minValue, double maxValue)
    Computes the variance based threshold using Otsu's method from an input image.
    static int computeOtsu2​(int[] histogram, int length, int totalPixels)
    Computes a modified modified Otsu threshold which maximizes the distance from the distributions means.
    static int computeOtsu2​(ImageGray input, int minValue, int maxValue)
    Computes the variance based threshold using a modified Otsu method from an input image.
    static <T extends ImageGray<T>>
    GrayU8
    localGaussian​(T input, @Nullable GrayU8 output, ConfigLength width, double scale, boolean down, T work1, @Nullable ImageGray work2)
    Thresholds the image using a locally adaptive threshold that is computed using a local square region centered on each pixel.
    static <T extends ImageGray<T>>
    GrayU8
    localMean​(T input, GrayU8 output, ConfigLength width, double scale, boolean down, T work1, T work2, @Nullable GrowArray work3)
    Thresholds the image using a locally adaptive threshold that is computed using a local square region centered on each pixel.
    static <T extends ImageGray<T>>
    GrayU8
    localNiblack​(T input, @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
    Applies Niblack thresholding to the input image.
    static <T extends ImageGray<T>>
    GrayU8
    localNick​(T input, @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
    Applies NICK thresholding to the input image.
    static <T extends ImageGray<T>>
    GrayU8
    localOtsu​(T input, @Nullable GrayU8 output, boolean otsu2, ConfigLength width, double tuning, double scale, boolean down)  
    static <T extends ImageGray<T>>
    GrayU8
    localSauvola​(T input, @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
    Applies Sauvola thresholding to the input image.
    static <T extends ImageGray<T>>
    GrayU8
    localWolf​(T input, @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
    Applies Wolf thresholding to the input image.
    protected static <T extends ImageGray<T>>
    GrayU8
    niblackFamily​(T input, @Nullable GrayU8 output, ConfigLength width, float k, boolean down, ThresholdNiblackFamily.Variant variant)  
    static <T extends ImageGray<T>>
    GrayU8
    threshold​(T input, @Nullable GrayU8 output, double threshold, boolean down)
    Applies a global threshold across the whole image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GThresholdImageOps

      public GThresholdImageOps()
  • Method Details

    • computeOtsu

      public static double computeOtsu​(ImageGray input, double minValue, double maxValue)

      Computes the variance based threshold using Otsu's method from an input image. Internally it uses computeOtsu(int[], int, int) and GImageStatistics.histogram(ImageGray, double, int[])

      Parameters:
      input - Input gray-scale image
      minValue - The minimum value of a pixel in the image. (inclusive)
      maxValue - The maximum value of a pixel in the image. (inclusive)
      Returns:
      Selected threshold.
    • computeOtsu2

      public static int computeOtsu2​(ImageGray input, int minValue, int maxValue)

      Computes the variance based threshold using a modified Otsu method from an input image. Internally it uses computeOtsu2(int[], int, int) and GImageStatistics.histogram(ImageGray, double, int[])

      Parameters:
      input - Input gray-scale image
      minValue - The minimum value of a pixel in the image. (inclusive)
      maxValue - The maximum value of a pixel in the image. (inclusive)
      Returns:
      Selected threshold.
    • computeOtsu

      public static int computeOtsu​(int[] histogram, int length, int totalPixels)
      Computes the variance based Otsu threshold from a histogram directly. The threshold is selected by minimizing the spread of both foreground and background pixel values.
      Parameters:
      histogram - Histogram of pixel intensities.
      length - Number of elements in the histogram.
      totalPixels - Total pixels in the image
      Returns:
      Selected threshold
    • computeOtsu2

      public static int computeOtsu2​(int[] histogram, int length, int totalPixels)
      Computes a modified modified Otsu threshold which maximizes the distance from the distributions means. In extremely sparse histograms with the values clustered at the two means Otsu will select a threshold which is at the lower peak and in binary data this can cause a total failure.
      Parameters:
      histogram - Histogram of pixel intensities.
      length - Number of elements in the histogram.
      totalPixels - Total pixels in the image
      Returns:
      Selected threshold
    • computeLi

      public static double computeLi​(ImageGray input, double minValue, double maxValue)

      Computes Li's Minimum Cross Entropy thresholding from an input image. Internally it uses computeLi(int[], int) and GImageStatistics.histogram(ImageGray, double, int[])

      Parameters:
      input - Input gray-scale image
      minValue - The minimum value of a pixel in the image. (inclusive)
      maxValue - The maximum value of a pixel in the image. (inclusive)
      Returns:
      Selected threshold.
    • computeLi

      public static int computeLi​(int[] histogram, int length)
      Implements Li's Minimum Cross Entropy thresholding method This implementation is based on the iterative version (Ref. 2) of the algorithm. 1) Li C.H. and Lee C.K. (1993) "Minimum Cross Entropy Thresholding" Pattern Recognition, 26(4): 617-625 2) Li C.H. and Tam P.K.S. (1998) "An Iterative Algorithm for Minimum Cross Entropy Thresholding"Pattern Recognition Letters, 18(8): 771-776 3) Sezgin M. and Sankur B. (2004) "Survey over Image Thresholding Techniques and Quantitative Performance Evaluation" Journal of Electronic Imaging, 13(1): 146-165 http://citeseer.ist.psu.edu/sezgin04survey.html Ported to ImageJ plugin by G.Landini from E Celebi's fourier_0.8 routines Ported from Imagej code (https://imagej.nih.gov/ij/developer/source/) to BoofCV by Nico Stuurman
      Parameters:
      histogram - Histogram of pixel intensities.
      length - Number of elements in the histogram.
      Returns:
      Selected threshold
    • computeHuang

      public static double computeHuang​(ImageGray input, double minValue, double maxValue)

      Computes Huang's Minimum fyzzy thresholding from an input image. Internally it uses computeHuang(int[], int) and GImageStatistics.histogram(ImageGray, double, int[])

      Parameters:
      input - Input gray-scale image
      minValue - The minimum value of a pixel in the image. (inclusive)
      maxValue - The maximum value of a pixel in the image. (inclusive)
      Returns:
      Selected threshold.
    • computeHuang

      public static int computeHuang​(int[] histogram, int length)
      Implements Huang's fuzzy thresholding method Uses Shannon's entropy function (one can also use Yager's entropy function) Huang L.-K. and Wang M.-J.J. (1995) "Image Thresholding by Minimizing the Measures of Fuzziness" Pattern Recognition, 28(1): 41-51 M. Emre Celebi 06.15.2007 Ported to ImageJ plugin by G.Landini from E Celebi's fourier_0.8 routines Ported from Imagej code (https://imagej.nih.gov/ij/developer/source/) to BoofCV by Nico Stuurman
      Parameters:
      histogram - Histogram of pixel intensities.
      length - Number of elements in the histogram.
      Returns:
      Selected threshold
    • computeEntropy

      public static double computeEntropy​(ImageGray input, double minValue, double maxValue)

      Computes a threshold which maximizes the entropy between the foreground and background regions. See computeEntropy(int[], int, int) for more details.

      Parameters:
      input - Input gray-scale image
      minValue - The minimum value of a pixel in the image. (inclusive)
      maxValue - The maximum value of a pixel in the image. (inclusive)
      Returns:
      Selected threshold.
      See Also:
      GImageStatistics.histogram(ImageGray, double, int[])
    • computeEntropy

      public static int computeEntropy​(int[] histogram, int length, int totalPixels)

      Computes a threshold which maximizes the entropy between the foreground and background regions. See [1] for algorithmic details, which cites [2].

      [1] E.R. Davies "Machine Vision Theory Algorithms Practicalities" 3rd Ed. 2005. pg. 124
      [2] Hannah, Ian, Devesh Patel, and Roy Davies. "The use of variance and entropic thresholding methods for image segmentation." Pattern Recognition 28.8 (1995): 1135-1143.

      Parameters:
      histogram - Histogram of pixel intensities.
      length - Number of elements in the histogram.
      totalPixels - Total pixels in the image
      Returns:
      Selected threshold
    • threshold

      public static <T extends ImageGray<T>> GrayU8 threshold​(T input, @Nullable @Nullable GrayU8 output, double threshold, boolean down)
      Applies a global threshold across the whole image. If 'down' is true, then pixels with values ≤ to 'threshold' are set to 1 and the others set to 0. If 'down' is false, then pixels with values > to 'threshold' are set to 1 and the others set to 0.
      Parameters:
      input - Input image. Not modified.
      output - (Optional) Binary output image. If null a new image will be declared. Modified.
      threshold - threshold value.
      down - If true then the inequality ≤ is used, otherwise if false then > is used.
      Returns:
      binary image.
    • localMean

      public static <T extends ImageGray<T>> GrayU8 localMean​(T input, GrayU8 output, ConfigLength width, double scale, boolean down, @Nullable T work1, @Nullable T work2, @Nullable @Nullable GrowArray work3)

      Thresholds the image using a locally adaptive threshold that is computed using a local square region centered on each pixel. The threshold is equal to the average value of the surrounding pixels times the scale. If down is true then b(x,y) = I(x,y) ≤ T(x,y) * scale ? 1 : 0. Otherwise b(x,y) = I(x,y) > T(x,y) * scale ? 0 : 1

      NOTE: Internally, images are declared to store intermediate results. If more control is needed over memory call the type specific function.

      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      scale - Scale factor used to adjust threshold
      down - Should it threshold up or down.
      work1 - (Optional) Internal workspace. Can be null
      work2 - (Optional) Internal workspace. Can be null
      Returns:
      binary image.
    • localGaussian

      public static <T extends ImageGray<T>> GrayU8 localGaussian​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, double scale, boolean down, @Nullable T work1, @Nullable @Nullable ImageGray work2)

      Thresholds the image using a locally adaptive threshold that is computed using a local square region centered on each pixel. The threshold is equal to the gaussian weighted sum of the surrounding pixels times the scale. If down is true then b(x,y) = I(x,y) ≤ T(x,y) * scale ? 1 : 0. Otherwise b(x,y) = I(x,y) > T(x,y) * scale ? 0 : 1

      NOTE: Internally, images are declared to store intermediate results. If more control is needed over memory call the type specific function.

      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      scale - Scale factor used to adjust threshold
      down - Should it threshold up or down.
      work1 - (Optional) Internal workspace. Can be null
      work2 - (Optional) Internal workspace. Can be null
      Returns:
      binary image.
    • localOtsu

      public static <T extends ImageGray<T>> GrayU8 localOtsu​(T input, @Nullable @Nullable GrayU8 output, boolean otsu2, ConfigLength width, double tuning, double scale, boolean down)
      See Also:
      FactoryThresholdBinary.localOtsu(ConfigLength, double, boolean, boolean, double, Class)
    • localNiblack

      public static <T extends ImageGray<T>> GrayU8 localNiblack​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
      Applies Niblack thresholding to the input image. Intended for use with text image.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      k - Positive parameter used to tune threshold. Try 0.3
      down - Should it threshold up or down.
      Returns:
      binary image
      See Also:
      ThresholdNiblackFamily
    • localSauvola

      public static <T extends ImageGray<T>> GrayU8 localSauvola​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
      Applies Sauvola thresholding to the input image. Intended for use with text image.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      k - Positive parameter used to tune threshold. Try 0.3
      down - Should it threshold up or down.
      Returns:
      binary image
      See Also:
      ThresholdNiblackFamily
    • localWolf

      public static <T extends ImageGray<T>> GrayU8 localWolf​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
      Applies Wolf thresholding to the input image. Intended for use with text image.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      k - Positive parameter used to tune threshold. Try 0.3
      down - Should it threshold up or down.
      Returns:
      binary image
      See Also:
      ThresholdNiblackFamily
    • niblackFamily

      protected static <T extends ImageGray<T>> GrayU8 niblackFamily​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, float k, boolean down, ThresholdNiblackFamily.Variant variant)
    • localNick

      public static <T extends ImageGray<T>> GrayU8 localNick​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, float k, boolean down)
      Applies NICK thresholding to the input image. Intended for use with text image.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      k - Positive parameter used to tune threshold. Try -0.1 to -0.2
      down - Should it threshold up or down.
      Returns:
      binary image
      See Also:
      ThresholdNick
    • blockMinMax

      public static <T extends ImageGray<T>> GrayU8 blockMinMax​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, double scale, boolean down, double textureThreshold)
      Applies a threshold to an image by computing the min and max values in a regular grid across the input image. See ThresholdBlockMinMax for the details.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      scale - Scale factor used to adjust threshold
      down - Should it threshold up or down.
      textureThreshold - If the min and max values are within this threshold the pixel will be set to 1.
      Returns:
      Binary image
    • blockMean

      public static <T extends ImageGray<T>> GrayU8 blockMean​(T input, @Nullable @Nullable GrayU8 output, ConfigLength width, double scale, boolean down)
      Applies a threshold to an image by computing the mean values in a regular grid across the input image. See ThresholdBlockMean for the details.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      scale - Scale factor used to adjust threshold
      down - Should it threshold up or down.
      Returns:
      Binary image
    • blockOtsu

      public static <T extends ImageGray<T>> GrayU8 blockOtsu​(T input, @Nullable @Nullable GrayU8 output, boolean otsu2, ConfigLength width, double tuning, double scale, boolean down)
      Applies a threshold to an image by computing the Otsu threshold in a regular grid across the input image. See ThresholdBlockOtsu for the details.
      Parameters:
      input - Input image.
      output - (optional) Output binary image. If null it will be declared internally.
      width - Width of square region.
      tuning - Tuning parameter. 0 = regular Otsu
      down - Should it threshold up or down.
      Returns:
      Binary image