A Julia package for analyzing a one-dimensional histogram and automatically choosing a threshold which partitions the histogram into two parts.
A full list of algorithms can be found in the documentation. The algorithms were devised in the context of image processing applications but could prove useful in a variety of scenarios.
The general usage pattern is:
t = find_threshold(algorithm::ThresholdAlgorithm, histogram::AbstractArray, edges::AbstractRange)
length(histogram) must match
Suppose one wants to binarize an image. Binarization requires choosing a grey level (a threshold
t) such that all pixel intensities below that threshold are set to black and all intensities equal or above the threshold are set to white. One can attempt to choose a reasonable threshold automatically by analyzing the distribution of intensities in the image.
using HistogramThresholding using TestImages # For the moonsurface image. using ImageContrastAdjustment # For the build_histogram() function. img = testimage("moonsurface") edges, counts = build_histogram(img,256) #= The `counts` array stores at index 0 the frequencies that were below the first bin edge. Since we are seeking a threshold over the interval partitioned by `edges` we need to discard the first bin in `counts` so that the dimensions of `edges` and `counts` match. =# t = find_threshold(UnimodalRosin(), counts[1:end], edges) # The threshold `t` can now be used to determine which intensities should be # set to 0 (black), and which intensities should be set to 1 (white).