CImage:Set


The Set method sets the pixel value 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 works for any image data type. If you know in advance that the image data type is either numeric or RGB, you can use the faster methods Setn and Setr. However, if working with only a small number of pixels, the difference in speed between the various methods usually is not important.

Syntax

CImage:Set( val )

CImage:Set( x[], val )

CImage:Set( x, val )

CImage:Set( x, y, val )

CImage:Set( x, y, z, val )

where

    val 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.

Example

The following script shows an image file located at path sPath being opened and the pixel value at column 53, row 100, being set to value 180.5:

I = CImage:new()

-- Create a CImage

I:Open( sPath )

-- Open the image from file path sPath.

I:Set( {53,100,10}, 180.5 )

-- Set the pixel value at x,y,z to 180.5

I:Save()

-- save the image

Related Topics

Gets

Setn

Setr

SetRegionVal

CImage class