# Histogram-Based Double Thresholding

This code snippet shows how to perform a double thresholding operation. The low and high threshold values are computed according to the minimum residue method based on an histogram.

## C++

```cpp
#include <eVision/EasyImage/EasyImage.h>
```

```cpp
using namespace eVision;
// Images constructor
EImageBW8 srcImage;
EImageBW8 dstImage;
// Histogram constructor
EBWHistogramVector histo;
// Compute the histogram
EasyImage::Histogram(&srcImage, &histo);
// Compute the low and high threshold values automatically
// (and the average pixel values below, between and above the threshold)
EThreeLevelsMinResidueThreshold result = EasyImage::ThreeLevelsMinResidueThreshold(histo);
// Source and destination images must have the same size
dstImage.SetSize(&srcImage);
// Perform the double thresholding
EasyImage::DoubleThreshold(&srcImage, &dstImage, result.LowThreshold.Value, result.HighThreshold.Value);
```

#### SEE ALSO
[`EasyImage::Histogram`](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a844bd52f1e6c61fe0264412ed74d15de) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab9c24a850843e901bd1dc7fc360376b5) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ad1a8be6eacbbef1eef655ebdfc015aa9), [`EasyImage::ThreeLevelsMinResidueThreshold`](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#abf03357d915f3dadf2283f3a38d82c21) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab8bc21228297b7e3c48df54483ee8a61) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a48883f5410b81a2d6723ada0c7b8f0a8), [`EasyImage::DoubleThreshold`](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a2a224c0765addcb26073a721571da48d) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#a08f4bdaca7cad63ab81d4c16ce161b93) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ae759f1761e42e4970b80895e723912f2)

## C#

```cs
using eVision;
```

```cs
// Images constructor
EImageBW8 srcImage = new EImageBW8();
EImageBW8 dstImage = new EImageBW8();
// Histogram constructor
EBWHistogramVector histo = new EBWHistogramVector();
// Compute the histogram
EasyImage.Histogram(srcImage, histo);
// Compute the low and high threshold values automatically
// (and the average pixel values below, between and above the threshold)
EThreeLevelsMinResidueThreshold result = EasyImage.ThreeLevelsMinResidueThreshold(histo);
// Source and destination images must have the same size
dstImage.SetSize(srcImage);
// Perform the double thresholding
EasyImage.DoubleThreshold(srcImage, dstImage, result.LowThreshold.Value, result.HighThreshold.Value);
```

#### SEE ALSO
[`EasyImage.Histogram`](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab9c24a850843e901bd1dc7fc360376b5) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a844bd52f1e6c61fe0264412ed74d15de) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ad1a8be6eacbbef1eef655ebdfc015aa9), [`EasyImage.ThreeLevelsMinResidueThreshold`](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab8bc21228297b7e3c48df54483ee8a61) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#abf03357d915f3dadf2283f3a38d82c21) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a48883f5410b81a2d6723ada0c7b8f0a8), [`EasyImage.DoubleThreshold`](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#a08f4bdaca7cad63ab81d4c16ce161b93) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a2a224c0765addcb26073a721571da48d) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ae759f1761e42e4970b80895e723912f2)

## Python

```py
import eVision
# Images constructor
src_image = eVision.EImageBW8()
dst_image = eVision.EImageBW8()
# Histogram constructor
histo = eVision.EBWHistogramVector()
# Compute the histogram
eVision.EasyImage.Histogram(src_image, histo)
# Compute the low and high threshold values automatically
# (and the average pixel values below, between and above the threshold)
result = eVision.EasyImage.ThreeLevelsMinResidueThreshold(histo)
# Source and destination images must have the same size
dst_image.SetSize(src_image)
# Perform the double thresholding
eVision.EasyImage.DoubleThreshold(src_image, dst_image, result.LowThreshold.Value, result.HighThreshold.Value)
```

#### SEE ALSO
[`EasyImage.Histogram`](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ad1a8be6eacbbef1eef655ebdfc015aa9) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a844bd52f1e6c61fe0264412ed74d15de) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab9c24a850843e901bd1dc7fc360376b5), [`EasyImage.ThreeLevelsMinResidueThreshold`](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a48883f5410b81a2d6723ada0c7b8f0a8) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#abf03357d915f3dadf2283f3a38d82c21) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#ab8bc21228297b7e3c48df54483ee8a61), [`EasyImage.DoubleThreshold`](../../../../../doxygen_python/classeVision_1_1EasyImage.html#ae759f1761e42e4970b80895e723912f2) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a2a224c0765addcb26073a721571da48d) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#a08f4bdaca7cad63ab81d4c16ce161b93)
