IC Imaging Control C++



Y16 is a 16-bit grayscale format. The organization of the pixels in the image buffer is from left to right and top down.

Memory Layout

Every pixel is stored as an little-endian unsigned 16-bit integer value.

Some sensors only support 10-bit or 12-bit pixel data. In this case, the least significant bits are don't-care values.

How to read and write pixel data

A video capture device, video format, FrameSnapSink, which defines the image data color format must have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of Y16.

First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, we start live mode and call FrameHandlerSink::snapImages.

Accessing the buffer

The following code retrieves a pointer to the image data. Please note, that getPtr() returns a BYTE pointer which will be type-casted to an uint16_t pointer. This makes it much easier to access the pixel data since Y16 is a 16-bit format.

// Y16 Images are stored top-down, so the upper left pixel starts at byte 0.
// 2 Byte represent one pixel.
uint16_t* pImgData = (uint16_t*)pActiveBuf->getPtr();

In this example, we want to output the first (upper left hand) pixel of the image and manipulate the first 3. As previously mentioned, the image data is stored top down. Therefore, pImgData points to the first pixel of the first line in the buffer.

// The Y16 pixel values exactly map unsigned 16-bit integers:
uint16_t val0 = pImgData[0];
uint16_t val1 = pImgData[1];
printf( "\nImage buffer pixel format is eY16\n" );
printf( "Pixel 1 (Y16): %d\n", val0 );
printf( "Pixel 2 (Y16): %d\n", val1 );

Manipulating Image Data

Now we set the upper left three pixels to black, gray and white:

pImgData[0] = 0;        // Set the first pixel to BLACK
pImgData[1] = 32768;    // Set the second pixel to GRAY
pImgData[2] = 65535;    // Set the third pixel to WHITE
// We save the buffer as TIFF, so that other software can view it.
saveToFileTIFF( *pActiveBuf, "Y16.tiff" );

To check the result, just open the saved image and examine the upper left pixels. They should look as follows:


<< Accessing an Image Buffer

Get in touch with us

About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us