CStats:Sum


The Sum method computes the sum of a 1-dimensional array, CImage, or list of numbers. Compared with the Mean and several other class methods, this does not return the standard deviation. The array and list parameters must contain a mixture of numbers and strings that can be converted to numbers.

Syntax

nSum = CStats:Sum( CImage, CRect )

nSum = CStats:Sum( CImage )

nSum = CStats:Sum( table )

nSum = CStats:Sum( n1, n2, n3, ... )

bullet.gif    CRect is a bounding rectangle for the CImage object.

bullet.gif    table is a 1-dimensional array containing numbers.

bullet.gif    n1, n2, n3, ... may be a mixture of numbers and strings that can be converted to numbers.

bullet.gif    On success, returns the sum of the data.

bullet.gif    On failure, returns 0.

Examples

In these examples, note the use of both S and s; these are independent variables because lua is case-sensitive.

tbl = {}

-- create a table and fill it with values

S = new_stats()

 

s = S:Sum( tbl )

-- calculate the sum of a 1-dimensional array.

There is also a global function sum that computes the sum without using the CStats class.

Suppose a CImage I exists. The following script returns the sum of 600 pixels in the corner of the image.

S = new_stats()

-- create a CStats object

s = S:Sum( I, new_rect( 1,20,1,30 )

-- computes values inside the CRect

Printf("sum=%lg\n", s )

-- list the result

S:delete()

-- when done with S, delete it

Related Topics

CStats class, CImage class, CRect class, Mean, sum, Stats, Skewness, Kurtosis


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.