Skip to content

betttris13/HistogramThresholding.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HistogramThresholding.jl

Build Status Build Status Codecov

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)

where length(histogram) must match length(edges).

Example

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). 

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Julia 100.0%