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++¶
#include <eVision/EasyImage/EasyImage.h>
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);
C#¶
using eVision;
// 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);
Python¶
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)