The RGB8 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 bottom up. In other words: The first byte of the image buffer corresponds to the first pixel of the last line of the image.
A video capture device, video format, FrameHandlerSink with a ImageBuffers collections, 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 RGB8.
First of all, we have to capture an image. Otherwise, the image buffer would be empty. To do so, live mode is started and FrameHandlerSink.SnapImage is called.
To access the bytes of the image buffer, you can write buf[column,line] in C# and buf(column,line) in VB.NET.
In this example, we want to read out the first (upper left) two pixels of the image. In a second step we manipulate the first 3 pixels. Because RGB images are stored bottom-up, the index of the first line is lines-1.
' RGB is bottom-up, the first line has index (lines-1) Dim y As Integer y = buf.Lines - 1 Dim txt As String txt = "Image buffer pixel format is RGB8" & vbCrLf txt = txt & "Pixel 1: " & ImageData(0, y) & vbCrLf txt = txt & "Pixel 2: " & ImageData(1, y) txtOutput.Text = txt
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.
' Set the first pixel to 0 (black) ImageData(0, y) = 0 ' Set the second pixel to 128 (gray) ImageData(1, y) = 128 ' Set the third pixel to 255 (white) ImageData(2, y) = 255 buf.SaveAsBitmap "RGB8.png", ICY8 buf.ReleaseImageData ImageData End Sub Private Sub cmdY800_Click() Dim buf As ImageBuffer Set buf = GrabImage("Y800") Dim ImageData As Variant ImageData = buf.GetImageData '<<y800print ' Y800 is top-down, the first line has index 0 Dim y As Integer y = 0 Dim txt As String txt = "Image buffer pixel format is Y800" & vbCrLf txt = txt & "Pixel 1: " & ImageData(0, y) & vbCrLf txt = txt & "Pixel 2: " & ImageData(1, y) txtOutput.Text = txt
To check the result, open the saved image and take a look at the upper left hand pixels. They should look as follows:
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.