TMedian
The TMedian function returns the median and standard deviation of a data collection table. The collection can be a Lua table or an object of type CImage, CArray, or CMatrix.
nMedian, nStdDev, nStatus = TMedian( table )
nMedian, nStdDev, nStatus = TMedian( CImage )
nMedian, nStdDev, nStatus = TMedian( CArray )
nMedian, nStdDev, nStatus = TMedian( CMatrix )
where
table, CImage, CArray, or CMatrix contain the data.
nMean and nStdDev are the mean and standard deviation of the data.
nStatus is the success code from the calculation (non-zero on failure).
All aergument types 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.
The following script returns the median and standard deviation in a table of 1 million random numbers.
|
-- create a table of numbers |
|
-- find the median & standard deviation |
|
-- list the result |
The next script returns the median value for pixels inside a rectangle at the corner of a CImage.
|
-- attach the topmost image window |
|
-- make sure an image window is on top |
|
-- rectangle for corner of image |
|
-- use the current image in the CImageView |
|
-- list the result |