CStats:ContraMean


The ContraMean method computes the mean value of a data sample using contra-harmonic mean estimation to reduce the influence of deviant pixels. The sample may be a Lua table or a class object of type CImage, CArray, or CMatrix. For CImage and CMatrix objects, an optional CRect object can be used to define the points used in the calculation.

Syntax

nMean, nStdDev = CStats:ContraMean( table, nExp )

nMean, nStdDev = CStats:ContraMean( CImage, nExp )

nMean, nStdDev = CStats:ContraMean( CImage, nExp, CRect )

nMean, nStdDev = CStats:ContraMean( CArray, nExp )

nMean, nStdDev = CStats:ContraMean( CArray, nExp, CRect )

nMean, nStdDev = CStats:ContraMean( CMatrix, nExp )

where

    table is a lua table containing the data.

    CImage, CArray, and CMatrix are class objects containing the data to measure,

    CRect is a CRect rectangle object that defines the region to measure.

    nExp is the exponent parameter of the contra mean.

    nMean and nStdDev are the mean and standard deviation, respectively. On failure, 0,0 is returned.

  

This method uses the contra-harmonic mean statistic which assigns weights to values based upon their distance from the mean value. No rejection ("clipping") is performed. In contrast to the geometric mean, this method can be tuned to assign less weight to values lying above the sample or to values lying below the sample mean. The positive or negative tail bias depends upon the value of the exponent parameter and the severity of the weighting depends upon the absolute value of the exponent parameter.

For an exponent parameter of value e, the statistic is computed using a ratio of powers for each sample member x, as shown below. (Note: The symbol ^ denotes raising a number to a power, as in 2^3 = 8):

     Statistic = Sum( x^(e+1)/x^e ).

Thus

    e=0 gives the arithmetic mean.

    e<0 gives more weight to negative outliers.

    e>0 gives more weight to positive outliers.

Examples

Suppose a CImage I and a CRect R exist. The following script returns the contra-mean value inside a rectangle on the image:

S = CStats:new()

-- create a CStats object

power = 0.5

-- reduce the weight of negative outliers

nVal = S:ContraMean( I, power, R )

-- return the contra-harmonic mean value

Printf("mean=%lg\n", nVal)

-- list the result

The following script returns the contra-mean value for a table of data using power=0.5:

S = CStats:new()

-- create a CStats object

t = { 4, 4, 2, 5, 6.4, -1.42, -12, 3.4 }

-- create some data in a table

Printf("mean=%lg\n", S:ContraMean(t,0.5) )

-- list the result

Related Topics

GeomMean

YpMean

CStats Class