TMax


The TMax function returns the maximum value found in a data collection. The collection can be a Lua array or a class object of type CImage, CArray, or CMatrix. To process a variable list of values and tables, use the slower VMax function. Also see the CStats:Max method.

Syntax

nMax, nIndex, nStatus = TMax( table )

nMax, nIndex, nStatus = TMax( CImage )

nMax, nIndex, nStatus = TMax( CArray )

nMax, nIndex, nStatus = TMax( CMatrix )

where

    table, CImage, CArray, or CMatrix contains the target data.

    nMax is the maximum value of the data.

    nIndex is the array index or image pixel location for the maximum value.

    nStatus is the success code from the calculation (non-zero on failure).

  

All data except for the CImage class use double precision real numbers having data type "double". The CImage class supports values ranging from byte to double plus other data types. Numeric values other than double can be processed by first converting the table to a CImage. Note that you do not have to assign or use the 2nd or 3rd return value.

If the Data is a multi-dimensional CImage, the returned location does not account for higher dimensions. For example, if nIndex = 2450 and the image has 1000 columns (the first dimension), then the maximum value is at column 450 in row 3.

Note: For a CMatrix, the returned value of nIndex can be difficult to untangle because the CMatrix does not require a fixed number of columns in each row.

The CStats:Max method also can be used to calculate the max value. Using the CStats class has the added ability to constrain the sample to a rectangular region of a CImage or CMatrix.

Examples

The following script returns the maximum value in a table of 1 million random numbers.

t = TRand( 1000000 )

-- create a table of numbers

v, n = TMax( t )

-- find the maximum value

Printf("Max=%lg at %d\n", v )

-- list the maximum value and location

  

The next script returns the maximum value for pixels in a CImage.

V = AttachView( "CImageView" )

-- attach the topmost image window

Assert( V and V:Count() > 0 )

-- make sure an image window is on top

v = TMax( V:GetImage() )

-- use the current image in the CImageView

Printf("Max=%lg\n", v )

-- list the maximum value

Related Topics

Table Functions

Variable Argument Functions

TMin, CImageView Class

Random

CStats class