Ocean
Ocean::CV::FrameVariance Class Reference

This class implements functions to determine the frame variance. More...

Static Public Member Functions

template<typename T , typename TIntegral >
static bool deviation1Channel8Bit (const T *frame, const TIntegral *integral, uint8_t *deviation, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int deviationPaddingElements, const unsigned int window)
 This functions determines the frame deviation of a 1 channel 8 bit frame. More...
 
template<typename T >
static bool deviation1Channel8Bit (const T *frame, uint8_t *deviation, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int deviationPaddingElements, const unsigned int window)
 This functions determines the deviation within a 1-channel 8 bit frame. More...
 
template<typename TElementType , typename TSummationType , typename TMultiplicationType , unsigned int tChannels>
static void imageStatistics (const TElementType *frame, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, double *mean=nullptr, double *variance=nullptr, double *standardDeviation=nullptr)
 Compute the per-channel mean, variance, and standard deviation over an image. More...
 

Detailed Description

This class implements functions to determine the frame variance.

Member Function Documentation

◆ deviation1Channel8Bit() [1/2]

template<typename T , typename TIntegral >
static bool Ocean::CV::FrameVariance::deviation1Channel8Bit ( const T *  frame,
const TIntegral *  integral,
uint8_t *  deviation,
const unsigned int  width,
const unsigned int  height,
const unsigned int  framePaddingElements,
const unsigned int  deviationPaddingElements,
const unsigned int  window 
)
static

This functions determines the frame deviation of a 1 channel 8 bit frame.

Parameters
frameOriginal frame to determine the variance for
integralBordered integral frame of the original frame with border size equal have of the specified window size, the border must be mirrored
deviationResulting deviation frame
widthThe width of the original frame
heightThe height of the original frame
framePaddingElementsThe number of padding elements at the end of each frame row, in elements, with range [0, infinity)
deviationPaddingElementsThe number of padding elements at the end of each deviation row, in elements, with range [0, infinity)
windowSize of the window must be odd, with range [1, infinity)
Returns
True, if succeeded

◆ deviation1Channel8Bit() [2/2]

template<typename T >
static bool Ocean::CV::FrameVariance::deviation1Channel8Bit ( const T *  frame,
uint8_t *  deviation,
const unsigned int  width,
const unsigned int  height,
const unsigned int  framePaddingElements,
const unsigned int  deviationPaddingElements,
const unsigned int  window 
)
static

This functions determines the deviation within a 1-channel 8 bit frame.


The function uses an integral image for the calculation of the deviation.

Parameters
frameThe frame for which the deviation will be determined, must be valid
deviationResulting deviation frame
widthThe width of the given frame, in pixel, with range [1, infinity)
heightThe height of the given frame, in pixel, with range [1, infinity)
framePaddingElementsThe number of padding elements at the end of each frame row, in elements, with range [0, infinity)
deviationPaddingElementsThe number of padding elements at the end of each deviation row, in elements, with range [0, infinity)
windowSize of the window must be odd, with range [1, min(width, height) * 2]
Returns
True, if succeeded
Template Parameters
TThe data type of the frame elements, either 'int8_t' or 'uint8_t'

◆ imageStatistics()

template<typename TElementType , typename TSummationType , typename TMultiplicationType , unsigned int tChannels>
void Ocean::CV::FrameVariance::imageStatistics ( const TElementType *  frame,
const unsigned int  width,
const unsigned int  height,
const unsigned int  framePaddingElements,
double *  mean = nullptr,
double *  variance = nullptr,
double *  standardDeviation = nullptr 
)
static

Compute the per-channel mean, variance, and standard deviation over an image.

The basic outline of the computation is this (this example assumes no multi-channel and no stride but the actual implementation supports both, of course):

T0 imagePixels[pixelCount] = { ... };
T1 sum = 0;
T1 squareSum = 0;
for (i = 0; i < pixelCount; ++i)
{
sum[i] += T1(imagePixels[i]);
squareSum[i] += T1(T2(imagePixel[i]) * T2(imagePixels[i]))
}
double mean = (double)sum / (double)pixelCount
double variance = ((double)squareSum / pixelCount) - (mean * mean);
double stddev = std::sqrt(variance)
// Type `T0` is the type of the pixel elements, `T1` is used for the summations and type `T2` is used for multiplications.
// This allows for a optimal control over how to compute and with what precision.
// Example configurations are:
// - `T0`=float, `T1`=float, `T2`=double
// - `T0`=unsigned char, `T1`=unsigned long long, `T2`=unsigned short
Note
The most related OpenCV function is cv::meanStdDev()
Parameters
frameThe input frame; mustn't be empty and must be a 1-channel image
widthThe width of the input image, range: [1, infinity)
heightThe height of the input image, range: [1, infinity)
framePaddingElementsOptional number of padding elements at the end of each source row, in elements, with range [0, infinity)
meanArray for the resulting per-channel mean values, will be ignored if set to nullptr otherwise it must have channels elements
varianceArray for the resulting per-channel variance, will be ignored if set to nullptr otherwise it must have channels elements
standardDeviationArray for the resulting per-channel standard deviations, will be ignored if set to nullptr otherwise it must have channels elements
Template Parameters
TElementTypeType of the elements of the pixels of the input image
TSummationTypeType used for the internal computation of the pixel sums (should be at least as large as TElementType), cf. function description for details
TMultiplicationTypeType used to compute the square values of pixels (allows control over integer vs. floating point multiplication), cf. function description for details
tChannelsNumber of channels of the input image, range: [1, infinity)

The documentation for this class was generated from the following file: