CImage:Mod


The Mod method computes the remainder (or modulus) resulting from dividing the image by another image or by a numeric value. The result replaces the current image.

Syntax

bSuccess = CImage:Mod( CImage2 )

bSuccess = CImage:Mod( value )

where

    CImage2 is another CImage object.

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

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

  

This method has a possibility of an illegal divide by 0 operation when the pixel of the operand image has a value of 0. Mira traps this condition and substitutes a replacement value into the output pixel. The replacement value is set for math operations using the SetMathErrVal method.

Examples

The following script loads two images from files sPath1 and sPath2 and calculates the modulus (remainder) of the first image divided by the second image:

SetMathErrVal( 1 )

-- sets the output pixel to 1 upon divide by 0 error.

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

-- calculate the modulus of I / I2

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

-- calculate the modulus of I / I2

The following script reads an image from a file and multiplies every pixel by 10.25:

I = CImage:new()

-- create a new CImage

I:Open(sPath)

-- load the image from a file named sPath

I = I % 10

-- calculate the modulus of I / 10

Related Topics

Math Operators

Div

CImage class