Class GThresholdImageOps
- java.lang.Object
-
- boofcv.alg.filter.binary.GThresholdImageOps
-
public class GThresholdImageOps extends java.lang.ObjectWeakly typed version ofThresholdImageOps.
-
-
Constructor Summary
Constructors Constructor and Description GThresholdImageOps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static intcomputeEntropy(ImageGray input, int minValue, int maxValue)Computes a threshold which maximizes the entropy between the foreground and background regions.static intcomputeEntropy(int[] histogram, int length, int totalPixels)Computes a threshold which maximizes the entropy between the foreground and background regions.static intcomputeOtsu(ImageGray input, int minValue, int maxValue)Computes the variance based threshold using Otsu's method from an input image.static intcomputeOtsu(int[] histogram, int length, int totalPixels)Computes the variance based Otsu threshold from a histogram directly.static <T extends ImageGray>
GrayU8localBlockMinMax(T input, GrayU8 output, int radius, 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>
GrayU8localGaussian(T input, GrayU8 output, int radius, double scale, boolean down, T work1, 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>
GrayU8localSauvola(T input, GrayU8 output, int radius, float k, boolean down)AppliesSauvolathresholding to the input image.static <T extends ImageGray>
GrayU8localSquare(T input, GrayU8 output, int radius, double scale, boolean down, T work1, T 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>
GrayU8threshold(T input, GrayU8 output, double threshold, boolean down)Applies a global threshold across the whole image.
-
-
-
Method Detail
-
computeOtsu
public static int computeOtsu(ImageGray input, int minValue, int maxValue)
Computes the variance based threshold using Otsu's method from an input image. Internally it uses
computeOtsu(int[], int, int)andGImageStatistics.histogram(ImageGray, int, int[])- Parameters:
input- Input gray-scale imageminValue- 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
-
computeEntropy
public static int computeEntropy(ImageGray input, int minValue, int 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 imageminValue- 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, int, 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> GrayU8 threshold(T input, 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.
-
localSquare
public static <T extends ImageGray> GrayU8 localSquare(T input, GrayU8 output, int radius, double scale, boolean down, T work1, T 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 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.radius- Radius of square region.scale- Scale factor used to adjust thresholddown- Should it threshold up or down.work1- (Optional) Internal workspace. Can be nullwork2- (Optional) Internal workspace. Can be null- Returns:
- binary image.
-
localGaussian
public static <T extends ImageGray> GrayU8 localGaussian(T input, GrayU8 output, int radius, double scale, boolean down, T work1, 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.radius- Radius of square region.scale- Scale factor used to adjust thresholddown- Should it threshold up or down.work1- (Optional) Internal workspace. Can be nullwork2- (Optional) Internal workspace. Can be null- Returns:
- binary image.
-
localSauvola
public static <T extends ImageGray> GrayU8 localSauvola(T input, GrayU8 output, int radius, float k, boolean down)
AppliesSauvolathresholding 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.radius- Radius of local region. Try 15k- Positive parameter used to tune threshold. Try 0.3down- Should it threshold up or down.- Returns:
- binary image
- See Also:
ThresholdSauvola
-
localBlockMinMax
public static <T extends ImageGray> GrayU8 localBlockMinMax(T input, GrayU8 output, int radius, 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. SeeThresholdSquareBlockMinMaxfor the details.- Parameters:
input- Input image.output- (optional) Output binary image. If null it will be declared internally.radius- Radius of square region.scale- Scale factor used to adjust thresholddown- 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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG