2.6.4.4 imgC2gray

Menu Information

Image: Conversion: Color to Gray

Brief Information

Convert to grayscale image

Command Line Usage

1.imgc2gray gray:=16;
2.imgc2gray img:=mat(1) oimg:=mat(2);

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Input Matrix img

Input

Image

<active>

Specifies the image to be manipulated. The default input is the active image.

Output Image oimg

Output

Image

<input>

Specifies the output image. By default, the output image is the same as the input image. See the syntax here.

Gray Scale gray

Input

int

8

Specifies the number of bits per screen pixel for the output grayscale image

Description

This function allows user to convert a color image to an 8-bit, 12-bit, or 16-bit grayscale image. The output grayscale image is created by calculating a weighted sum of the R, G and B components. The result image has similar levels of contrast to the original color image.

Examples

  • Code Sample
//Create a new folder in the Project Explorer
pe_mkdir Conversion path:=aa$;
pe_cd aa$;
//Create a matrix and import a sample image
window -t m;
path$ = System.path.program$;
fname$ = path$ + "samples\Image Processing and Analysis\leaves.jpg";
impimage;
window -r %h Original;
window -d;	//Duplicate the image
window -r %h BlueLeave;

imgC2gray;	//Convert to gray
imgUnsharpmask a:=80 r:=30; //Strenghen details

window -s T;	//Tile the windows horizontally

Algorithm

The computation uses L_GrayScaleBitmap() function from LEADTOOLS Main API. Please refer to the LEADTOOLS Main API Help file, Version 14 and read the L_GrayScaleBitmap topic.

References

LEADTOOLS Main API Help file, Version 14

Related X-Functions

imgBinary, imgAutoBinary, imgDynamicBinary, imgThreshold