CImage:Div


The Div method divides this image by another image or by a numeric value. The result replaces the current image.

Syntax

bSuccess = CImage:Div( CImage )

bSuccess = CImage:Div( 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.

  

This method has a possibility of an illegal divide by 0 operation when the pixel of the other 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 divides them:

SetMathErrVal( 1 )

-- output pixel set to 1 upon divide by 0 error

I = CImage:new()

-- create a new CImage

I:Open(sPath1)

-- load the image from the file sPath1

I2 = CImage:new()

-- create a new CImage

I2:Open(sPath2)

-- load the second image from the file sPath2

I:SetDatatype("float")

-- change data type for a more significant result

I:Div( I2 )

-- Divide I2 into 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

-- Divide I2 into I

The following script reads an image from a file and divides 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.25

-- Divide all pixels of I by 10.25

Related Topics

Math Operators

Mod

Mul

CImage class