The Y800 color format is an 8 bit monochrome format. Every pixel is represented by one byte. The organization of the pixels in the image buffer is from left to right and top down. In other words: The first byte of the image buffer corresponds to the first pixel of the first line of the image.
A video capture device, video format, FrameSnapSink must have been setup. The following code fragments show step-by-step how to access and manipulate the pixel data of Y800.
First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, live mode is started and FrameSnapSink.SnapSingle is called. This is all done by the GrabImage method.
To access the bytes of the image buffer, we create an instance of BufferAccessHelper so you can write buf[column,line] to access the individual bytes.
In this example, we want to read out the first (upper left hand) two pixels of the image. In a second step we manipulate the first 3 pixels. Because Y800 images are stored top-down, the index of the first line is 0.
[C#]
// Y800 is top-down, the first line has index 0 int y = 0; txtOutput.Text = "Image buffer pixel format is Y800\r\n"; txtOutput.Text += "Pixel 1: " + buf[0, y] + "\r\n"; txtOutput.Text += "Pixel 2: " + buf[1, y];
Instead of only reading pixel data, it is, of course, possible to manipulate the data as well. The following code sets the upper left hand pixel to black and the next 2 pixels to gray and white. After this manipulation, the image is saved to a BMP file.
[C#]
// Set the first pixel to 0 (black) buf[0, y] = 0; // Set the second pixel to 128 (gray) buf[1, y] = 128; // Set the third pixel to 255 (white) buf[2, y] = 255; TIS.Imaging.FrameExtensions.SaveAsBitmap(frame, "Y800.bmp");
To check the result, open the saved image and take a look at the upper left hand pixels. They should look as follows: