CImage:Sub


The Sub method subtracts another image or a numeric value from the current image. The result replaces the current image.

Syntax

bSuccess = CImage:Sub( CImage )

bSuccess = CImage:Sub( value )

where

    CImage is another CImage.

    value is a numeric value 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, subtracting two "short" integer images may result in values as low as -65536 but Mira truncates the result at -32768, the lowest value that can be expressed for a short integer number. If there is a chance of overflow and you want to accommodate the values, use SetDatatype to change to a "larger" datatype before calling Sub.

Examples

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:Sub( I2 )

-- Subtract image I2 from 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

-- Subtract I2 from I

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

I = CImage:new()

-- create a new CImage

I:Open(sPath)

-- load the image from a file named sPath

I = I - 10.25

-- Subtract 10.25 from all pixels of I

Related Topics

Math Operators

Add

CImage class