CStats:MaxClipMean CStats:Median

CStats:Mean


The Mean method computes the mean and standard deviation of numeric data. The data may be in the form of a lua array or a class object of type CImage, CArray, or CMatrix. For the CImage and CMatrix classes, you can optionally specify a rectangle that bounds the data region. For a CImage, the data may have multiple channels as with an RGB image.

Syntax

nMean, nSdev = CStats:Mean( Data, CRect* )

nMr,nSr, nMg,nMg, nMb,nMb = CStats:Mean( CImage, CRect* )

Remarks

Although this method returns two values, the mean and the standard deviation, you do not have to "catch" the standard deviation by assigning to a variable. For example,

m = S:Mean( T )

-- get the mean of table T.

m, sd = S:Mean( T )

-- gets the mean and standard deviation of table T.

If Mean is the last function in an expression, both values can be used implicitly, like

     Printf( "%lg +/- %lg, Mean(t) ).

Example

Suppose a CImage I exists. The following script returns the mean and standard deviation of 600 pixels in the corner of the image:

S = CStats:new()

-- create a CStats object

m, sd = S:Mean( I, CRect:new( 1,20,1,30 )

-- computes values inside the CRect

Printf("mean=%lg +/- %lg\n", m, sd )

-- list the result

S:delete()

-- when done with S, delete it

Related Topics

CStats, CImage, CRect