CImage:SetRegionVal
The SetRegionVal method sets the pixel values inside a rectangular region. The Setn and Setr methods may also be used but are not nearly as fast when used in a loop to set a large number of values.
bSuccess = CImage:SetRegionVal( nValue ) bSuccess = CImage:SetRegionVal( nValue, CRect ) bSuccess = CImage:SetRegionVal( nValue, CRect, nSigma ) where |
nValue is the value to assign to the region.
CRect is a CRect rectangle that describes the rectangle to set. If not specified or nil, the entire image is set.
nSigma is the sigma for a Gaussian random noise distribution.
bSuccess is the returned success code. On success it is true, otherwise false.
This method replaces the pixel values by a single value and Gaussian random noise. To set only the pixel value, pass nSigma=0. To add only noise, use nValue=0 or use the AddNoise method.
If the image has a numeric data type and you pass an RGB string for either nValue or nSigma, the RGB string is converted to an equivalent numeric intensity.
The following script opens an image from the file at sPath, then assigns the value 1800.5 to all pixels in columns 100:200 and rows 250:350:
|
-- Create a CImage |
|
-- Open the image from sPath. |
|
-- create a rectangle |
|
-- Set the new pixel value |
|
-- save the modified image |