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. // //////////////////////////////////////////////////////////////////// // 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.Value , highThr.Value);