CImage:Add


The Add method adds another image or a value to this image. The result replaces the current image.

Syntax

bSuccess = CImage:Add( CImage )

bSuccess = CImage:Add( value )

where

    CImage is another CImage.

    value is a number or a string that can be converted to a number.

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

  

For the byte, short, and ushort data types, Mira handles value overflow by truncating the output pixel value at the limits for the data type. For example, adding two "short" integer images may result in a pixel value as high as 65534 but Mira caps the result at 32767, the largest value that can be expressed as a short integer. If there is a chance of overflow and you want to accommodate the values, use SetDatatype to change to a "larger" Data type before calling Add.

Example

The following script loads two images from files sPath1 and sPath2 and adds them:

I = CImage:new()

-- create a new CImage

I2 = CImage:new()

-- create a new CImage

I:Open(sPath1)

-- load the first image from a file named sPath1

I2:Open(sPath2)

-- load the second image from a file named sPath2

I:Add( I2 )

-- perform the operation on image I

The same result can be accomplished using the + math operator:

I = CImage:new()

-- create a new CImage

I2 = CImage:new()

-- create a new CImage

I:Open(sPath1)

-- load the first image from a file named sPath1

I2:Open(sPath2)

-- load the second image from a file named sPath2

I = I + I2

-- Add I2 to I

The following script reads an image from a file and adds the value 10.25 to every pixel:

I = CImage:new()

-- create a new CImage

I:Open(sPath)

-- load the image from a file named sPath

I = I + 10.25

-- Add 10.25 to all pixels of I

I:Save()

-- save image back to file

Related Topics

CImage class, Math Operators, Sub