CImage:Mul


The Mul method multiplies this image by another image or a numeric value. The result replaces the current image.

Syntax

bSuccess = CImage:Mul( CImage2 )

bSuccess = CImage:Mul( value )

where

    CImage2 is another CImage.

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

    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, multiplying two short images may result in a pixel values above 1 billion and below -1 billion, but limits the result to the range [-32768, 32767]. To avoid this problem, you may wish to call SetDatatype to promote the current image to a "larger" data type such as long or float before performing the Mul operation. The fact that the two images may differ in data type is not a problem.

Examples

The following script loads two images from files sPath1 andsPath2 and multiplies them. In this example, assume that image 2 has a "short" integer data type so that overflow might occur if the current image has a data type of "byte", "short", or "ushort" type. This script avoids that problem:

I = CImage:new()

-- create a new CImage

I2 = CImage:new()

-- create a new CImage

I:Open(sPath1)

-- load the first image

I2:Open(sPath2)

-- load the second image

if ( I:GetDatatype() <= 3 ) then

-- if byte, short, or ushort

  I:SetDatatype("int")

-- convert I to long integer type

end

 

I:Mul( I2 )

-- Multiply I by 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

-- Multiply I by 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.25

-- Multiply all pixels of I by 10.25

Related Topics

Div

Math Operators

CImage class