CImage:Setr
The Setr method sets the pixel value of an RGB 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 numeric type images is Setn.
CImage:Setr( sRgbVal ) CImage:Setr( x[], sRgbVal ) CImage:Setr( x, sRgbVal ) CImage:Setr( x, y, sRgbVal ) CImage:Setr( x, y, z, sRgbVal ) where |
sRgbVal is a string containing RGB components, such as "25,45.35, 100". If only the sRgbVal 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 "100,100,100" are set to 0. The script uses Getr 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 |
|
-- get RGB pixel value as a triplet string |
|
-- split the returned pixel value into r,g,b |
|
-- if pixel i has value > 1,000 |
|
-- then set pixel i to 0,0,0 passed as a string |
|
|
|
|
|
-- 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 |
|
-- get RGB pixel value as a triplet string |
|
-- split the returned pixel value into r,g,b |
|
-- if pixel i has value > 1,000 |
|
-- then set pixel i to "0,0,0" |
|
|
|
|
|
|
|
-- save the image |