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.
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.
The following script returns the maximum value in a table of 1 million random numbers.
|
-- create a table of numbers |
|
-- find the maximum value |
|
-- list the maximum value and location |
The next script returns the maximum value for pixels in a CImage.
|
-- attach the topmost image window |
|
-- make sure an image window is on top |
|
-- use the current image in the CImageView |
|
-- list the maximum value |