CImage:ScaleLinVal


The ScaleLinVal method does a linear scaling by applying an offset and factor to each pixel value.

Syntax

bResult = CImage:ScaleLinVal( offset, factor )

bullet.gif    offset is the zero point value.

bullet.gif    factor is the multiplication factor.

bullet.gif    On success, this method returns true.

bullet.gif    On failure, this method returns false.

Remarks

This method duplicates the combination of Addx and Mulx methods. However, especially for integer pixel types, it better preserves the data precision by not truncating or rounding the intermediate result.

When applying this method to byte, short, and ushort pixel types, one should be especially concerned about value overflow in which the resulting pixel value exceeds the capabilities of the PixelTypes, Mira handles value overflow by truncating the output pixel value at the limits for the pixel type. For example, applying this method to a short type image may result in pixel values outside the range [-32768, 32767]. Although Mira automatically truncates the result to this range, you may need to retain the values that fall outside the pixel type limits. To avoid the truncation, you may wish to call SetPixelType to promote the current image to a "larger" pixel type, such as long or float, before performing the ScaleLinVal operation.

Example

The following script loads an image from files sPath, applies a linear luminance scaling, and displays the result. The applied scale coefficients are offset=400 and factor=1.552:

I = new_image()

-- create a new CImage

I:Open( sPath )

-- load the image

if I:GetPixelType() <= 3 then

-- if byte, short, or ushort

  I:SetPixelType("float")

-- convert I to 32 bit float type

end

 

I:ScaleLinVal( 400, 1.552 )

-- perform the operation on image I

I:Display()

 

I:delete()

 

Related Topics

CImage class, ScalePolyVal


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.