ImageGetPixelGrayΒΆ

ImageGetPixelGray returns the gray value of a pixel.

gray = ImageGetPixelGray(hImg, x, y)
grayMat = ImageGetPixelGray(hImg)

Return Value

gray is the gray value of the specified pixel in the range 0 to 255. If x or y is out of range the function returns the gray value of the pixel x=1, y=1. In case of an error the functions returns -1.

Parameters

hImg

hImg identifies the picture created with ImageCreate.

x

x is the horizontal pixel position in the range 1 to ImageGetWidth.

y

y is the vertical pixel position in the range 1 to ImageGetHeight.

Example

The following saves the gray value in a text file. The data file can be loaded with File=>More File Functions=>Load 3D Data Matrix. If the image size is big the image size should be reduced to approx. 500 * 500.

def image_save_pixel(hImg, ssFile)
{
    fp = fopen(ssFile, "wt");
    if (!fp) {
        return FALSE;
    }
    dx = ImageGetWidth(hImg);
    dy = ImageGetHeight(hImg);
    for (j in 1:dy) {
        for (i in 1:dx) {
            g = ImageGetPixelGray(hImg, i, j)
            fprintf(fp, "%d\t", g);
        }
        fprintf(fp, "\n");
    }
    fclose(fp);
    return TRUE;
}

History

Version Description
5.3.2  
5.2.0 New

id-552611