CImage:Setn
The Setn method sets the pixel value of a numeric data type at the specified image coordinates. The coordinates are unit-based, so that coordinates {1,1,...} correspond to the first pixel in the image array. This method is a faster, but less general version of the Set method. A specific method for setting pixels of RGB type images is Setr.
CImage:Setn( nVal ) CImage:Setn( x[], nVal ) CImage:Setn( x, nVal ) CImage:Setn( x, y, nVal ) CImage:Setn( x, y, z, nVal ) where |
nVal is a number. If only the nVal argument is passed, the entire image is set ot the value.
x[] is a coordinate array.
x,y, and z are column, row, and plane coordinates of the pixel.
To assign a single value to all pixels of the image, use the first form without coordinates. To set all pixels inside a rectangular region, use SetRegionVal.
The first script below shows the creation of a mask image in which all pixels with values above 1000 are set to 0. The script uses Getn to test the value, then changes it if necessary. In this case, every pixel is processed, so a single array index is used for the entire image:
|
-- Create a CImage |
|
-- Open the image from file path sPath. |
|
-- count the number of image pixels |
|
-- loop over all image pixels |
|
-- if pixel i has value > 1,000 |
|
-- then set pixel i to 0 |
|
|
|
|
|
-- save the image |
The next script creates a mask like the previous script but processes only a rectangular region of the image. This application therefore requires using 2 array indices to access only the rectangular region. The rectangular region is presumed to already be determined and have limits [nMinCol,nMaxCol:nMinRow,nMaxRow].
|
-- Create a CImage |
|
-- Open the image from file path sPath. |
|
-- count the number of image pixels |
|
-- loop over the row range |
|
-- loop over the column range |
|
-- if pixel i has value > 1,000 |
|
-- then set pixel i to 0 |
|
|
|
|
|
|
|
-- save the image |