2.1.12.5 image_to_gray


Description

convert Image Matrix Object to gray scale image


convert Image to gray scale image

Syntax

int image_to_gray( MatrixObject & mo, int nbits )


int image_to_gray( BITMAPHANDLE * pLBmp, int nbits )

Parameters

mo
[modify] Target matrix object(Image) to be convert.
nbits
[input] number of bits, Support 8, 12, 16 bits grayscale


pLBmp
[modify] Target Image Bitmap Handler
nbits
[input] number of bits, Support 8, 12, 16 bits grayscale

Return

SUCCESS or a LeadTools error number less than zero.


SUCCESS or a LeadTools error number less than zero.

Examples

Prior to compilation, load matdata_utils.c to the workspace by executing the following LabTalk command:

Run.LoadOC("Originlab\matdata_utils.c", 16);

To retain matdata_utils.c in the workspace for successive sessions, drag and drop the file from the Temporary folder to the System folder.

EX1

#include <..\originlab\matdata_utils.h>
//this example assumes that there is already an image in the active matrix sheet in MBook1 matrix book
void image_to_gray_ex1()
{
    MatrixObject        mobj;
    if (!mobj.Attach("MBook1"))
    {
        out_str("Attachment failed!");
    }
    int nbits = 8;
    image_to_gray(mobj, nbits);
}


EX2

#include <..\originlab\matdata_utils.h>
#include <image_utils.h>
//this example assumes that there is already an image in the active matrix sheet in MBook1 matrix book
void image_to_gray_ex2()
{
    MatrixObject        mobj;
    if (!mobj.Attach("MBook1"))
    {
        out_str("Attachment failed!");
    }
    Image img(mobj);
    if(!img.IsValid())
        return;
    BITMAPHANDLE* pLBmp = img.GetLBmp();
    int nbits = 12;
    image_to_gray(pLBmp, nbits);
}

Remark

See Also

is_image_grayscale

Header to Included

matdata_utils.h

Reference