# Histogram-Based Single Thresholding

This code snippet shows how to perform a minimum residue thresholding operation 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 single threshold (and the average pixel values below and above the threshold)
EHistogramThreshold histThreshold = EasyImage::HistogramThreshold(histo, (uint32_t)EThresholdMode_MinResidue);
// Source and destination images must have the same size
dstImage.SetSize(&srcImage);
// Perform the single thresholding
EasyImage::Threshold(&srcImage, &dstImage, histThreshold.Threshold);
```

#### 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::HistogramThreshold`](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a6d389ca5b5e94ce4dd06b0f9e20fb1e7) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#acdd6c18bf8436cce2f388d464d3f9cd0) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a63a92b4c45a14a1210e7351d46a1acfb)

## 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 single threshold (and the average pixel values below and above the threshold)
EHistogramThreshold histThreshold = EasyImage.HistogramThreshold(histo, unchecked((uint)EThresholdMode.MinResidue));
// Source and destination images must have the same size
dstImage.SetSize(srcImage);
// Perform the single thresholding
EasyImage.Threshold(srcImage, dstImage, histThreshold.Threshold);
```

#### 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.HistogramThreshold`](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#acdd6c18bf8436cce2f388d464d3f9cd0) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a6d389ca5b5e94ce4dd06b0f9e20fb1e7) [<sub>Python</sub>](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a63a92b4c45a14a1210e7351d46a1acfb)

## 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 single threshold (and the average pixel values below and above the threshold)
histThreshold = eVision.EasyImage.HistogramThreshold(histo, eVision.EThresholdMode.MinResidue)
# Source and destination images must have the same size
dst_image.SetSize(src_image)
# Perform the single thresholding
eVision.EasyImage.Threshold(src_image, dst_image, histThreshold.Threshold)
```

#### 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.HistogramThreshold`](../../../../../doxygen_python/classeVision_1_1EasyImage.html#a63a92b4c45a14a1210e7351d46a1acfb) [<sub>C++</sub>](../../../../../doxygen_cpp/classeVision_1_1EasyImage.html#a6d389ca5b5e94ce4dd06b0f9e20fb1e7) [<sub>.NET</sub>](../../../../../doxygen_cs/classeVision_1_1EasyImage.html#acdd6c18bf8436cce2f388d464d3f9cd0)
