CImage:AddNoise


The AddNoise method adds Gaussian random noise to the image pixel values.

Syntax

bSuccess = CImage:AddNoise( sigma )

bSuccess = CImage:AddNoise( CRect, sigma )

where

    sigma is the noise sigma, specified by a number or string.

    CRect is a CRect object that specifies a rectangle using 1-based coordinates. If omitted, the entire image is processed.

    bSuccess is the returned success code. On success it is true, otherwise false.

  

This method adds Gaussian random noise to the pixel values. The noise may be positive or negative relative to the existing pixel value. To set a pixel value plus noise, rather than add noise to the existing value, use SetRegionVal.

Example

The following script opens an image from the file at sPath, then add noise with a Gaussian sigma of 7.6 to all pixels in columns 100:200 and rows 250:350:

I = CImage:new()

-- Create a CImage

I:Open( sPath )

-- Open the image from sPath.

R = NewRect()

-- create a rectangle

R:Set( 100, 200, 250, 350 )

-- columns 100:200, rows 250:350

I:AddNoise( R, 7.6 )

-- add Gaussian noise to the rectangle

I:Save()

-- save the image

Related Topics

CImage class, SetRegionVal