Documentation Portal      

What are you looking for?

Histogram-Based Double Thresholding

Functional Guide | Reference: Histogram, ThreeLevelsMinResidueThreshold, DoubleThreshold

////////////////////////////////////////////////////////////////////
// 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. //
////////////////////////////////////////////////////////////////////
// Images constructor
EImageBW8 srcImage;
EImageBW8 dstImage;
// Histogram constructor
EBWHistogramVector histo;
// Variables
EBW8 lowThr;
EBW8 highThr;
float avgBelowThr, avgBetweenThr, avgAboveThr;
// ...
// 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)
EasyImage::ThreeLevelsMinResidueThreshold(&histo, lowThr, highThr, avgBelowThr, avgBetweenThr, avgAboveThr);
// Source and destination images must have the same size
dstImage.SetSize(&srcImage);
// Perform the double thresholding
EasyImage::DoubleThreshold(&srcImage, &dstImage, lowThr.Value, highThr.Value);
'////////////////////////////////////////////////////////////////////
'// 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. //
'////////////////////////////////////////////////////////////////////
' EasyImage context constructor
Dim EasyImage As New EasyImage
' Images constructor
Dim srcImage As New EImageBW8
Dim dstImage As New EImageBW8
' Histogram constructor
Dim histo As New EBWHistogramVector
' Variables
Dim lowThr As EBW8
Dim highThr As EBW8
Dim avgBelowThr As Single
Dim avgBetweenThr As Single
Dim avgAboveThr As Single
' ...
' 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)
EasyImage.ThreeLevelsMinResidueThreshold histo, lowThr, highThr, avgBelowThr, avgBetweenThr, avgAboveThr
' Source and destination images must have the same size
dstImage.SetSize srcImage.Width, srcImage.Height
' Perform the double thresholding
EasyImage.DoubleThresholdBW8 srcImage, dstImage, lowThr.value, highThr.value
////////////////////////////////////////////////////////////////////
// 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. //
////////////////////////////////////////////////////////////////////
// Images constructor
EImageBW8 srcImage= new EImageBW8();
EImageBW8 dstImage= new EImageBW8();
// Histogram constructor
EBWHistogramVector histo= new EBWHistogramVector();
// Variables
EBW8 lowThr= new EBW8();
EBW8 highThr= new EBW8();
float avgBelowThr, avgBetweenThr, avgAboveThr;
// ...
// 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)
EasyImage.ThreeLevelsMinResidueThreshold(histo, out lowThr, out highThr, out avgBelowThr, out avgBetweenThr, out avgAboveThr);
// Source and destination images must have the same size
dstImage.SetSize(srcImage);
// Perform the double thresholding
EasyImage.DoubleThreshold(srcImage, dstImage, lowThr.UINT32Value , highThr.UINT32Value);

Which API shall we display?

© 2019 EURESYS s.a.  -  About Documentation  -  Open Source Licenses  -  Open eVision 2.10.0.1121