Histogram-Based Statistics

This code snippet shows how to compute statistics based on an histogram.

C++

#include <eVision/EasyImage/EasyImage.h>
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// ...
// Histogram constructor
EBWHistogramVector histo;
// Compute the histogram
EasyImage::Histogram(&srcImage, &histo);
// Compute the average gray-level value
float average = EasyImage::AnalyseHistogram(&histo, EHistogramFeature_AveragePixelValue, 0, 255);
// Compute the gray-level standard deviation
float deviation = EasyImage::AnalyseHistogram(&histo, EHistogramFeature_PixelValueStdDev, 0, 255);

C#

using eVision;
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// ...
// Histogram constructor
EBWHistogramVector histo = new EBWHistogramVector();
// Compute the histogram
EasyImage.Histogram(srcImage, histo);
// Compute the average gray-level value
float average = EasyImage.AnalyseHistogram(histo, EHistogramFeature.AveragePixelValue, 0, 255);
// Compute the gray-level standard deviation
float deviation = EasyImage.AnalyseHistogram(histo, EHistogramFeature.PixelValueStdDev, 0, 255);

Python

import eVision
# Image constructor
src_image = eVision.EImageBW8()
# ...
# Histogram constructor
histo = eVision.EBWHistogramVector()
# Compute the histogram
eVision.EasyImage.Histogram(src_image, histo)
# Compute the average gray-level value
average = eVision.EasyImage.AnalyseHistogram(histo, eVision.EHistogramFeature.AveragePixelValue, 0, 255)
# Compute the gray-level standard deviation
deviation = eVision.EasyImage.AnalyseHistogram(histo, eVision.EHistogramFeature.PixelValueStdDev, 0, 255)