Image Statistics

This code snippet shows how to compute basic image statistics.

C++

#include <eVision/EasyImage/EImageStatisticsBW8.h>
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// ...
// Count the number of pixels above the threshold (128)
EImageStatisticsBW8 stats;
stats.SetImage(&srcImage);
stats.SetHighThreshold(128);
uint64_t count = stats.GetNumberOfPixelsAboveHighThreshold();
// Compute the pixels' average and standard deviation values
float stdDev = stats.GetPixelStdDev();
float average = stats.GetPixelAverage();
// Compute the image gravity center (pixels above threshold)
EPoint center = stats.GetGravityCenterOfPixelsAboveHighThreshold();

C#

using eVision;
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// ...
// Count the number of pixels above the threshold (128)
EBW8 threshold = new EBW8(128);
EImageStatisticsBW8 stats = new EImageStatisticsBW8();
stats.SetImage(srcImage);
stats.HighThreshold = threshold;
ulong count = stats.NumberOfPixelsAboveHighThreshold;
// Compute the pixels' average and standard deviation values
float stdDev = stats.PixelStdDev;
float average = stats.PixelAverage;
// Compute the image gravity center (pixels above threshold)
EPoint center = stats.GravityCenterOfPixelsAboveHighThreshold;

Python

import eVision
# Image constructor
src_image = eVision.EImageBW8()
# ...
# Count the number of pixels above the threshold (128)
threshold = eVision.EBW8(128)
stats = eVision.EImageStatisticsBW8()
stats.SetImage(src_image)
stats.HighThreshold = threshold
count = stats.NumberOfPixelsAboveHighThreshold
# Compute the pixels' average and standard deviation values
stdDev = stats.PixelStdDev
average = stats.PixelAverage
# Compute the image gravity center (pixels above threshold)
center = stats.GravityCenterOfPixelsAboveHighThreshold