CImage:Modx CImage:Mulx

CImage:Mul


The Mul method multiplies this image by another image. The result replaces the current image.

Syntax

bResult = CImage:Mul( CImage )

Remarks

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 2 images may differ in data type is not a problem.

Example

The following script fragment loads two images from files sPath1 andsPath2 , multiplies them, and saves the result of the first image back to its file. In addition, assume that image 2 has a short data type so that overflow can occur if the current image has a data type of byte, short, or ushort type. This code 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("long")

-- convert I to long integer type

end

 

I:Mul( I2 )

-- perform the operation on image I

I:Save()

 

I:delete()

 

I2:delete()

 

Related Topics

CImage