CImage:RectToTable
The RectToTable method copies the pixels from a rectangular region of a CImage into a 2-dimensional array. If the CImage has a numeric pixel type (e.g., "ushort", "float", etc.) then the array has numeric values. If the CImage has an rgb pixel type, then the array has rgb strings as values, for example "255,0,0" for pure red. See Pixel Types. Note that this method does not work with a 1-dimensional CImage. The inverse operation, pasting a rectangle region into a CImage, is done using the TableToRect method.
lua_table = CImage:RectToTable(nColMin, nColMax, nRowMin, nRowMax)
nColMin is the minimum column to extract.
nColMax is the maximum column to extract.
nRowMin is the minimum row to extract.
nRowMax is the maximum row to extract.
lua_table is a 2-dimensional array.
On failure, nil is returned.
The parameter order follows the standard order for describing image sections: [nMinCol:nMaxCol, nMinRow:nMaxRow]. Assuming the image has nCols total columns and nRows total rows, the specified limits are automatically chopped at the limits [1:nCols, 1:nRows].
The following script copies a 2-dimensional image rectangle [30:49,120:159] into a 2-dimensional array. The array size is (49-30+1) * (159-120+1) = 20*40 = 800 elements:
|
-- create a CImage object |
-- fill the image or open it from a file... |
|
|
-- create a 2-dimensional table from the rectangle |
CImage class, ColToTable, RowToTable, ToTable, arraytoimage, TableToRect, Table and Array Functions
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.