PDA

View Full Version : Using color formats



yklam
August 4, 2003, 10:18:50
Hello,

I was trying to extract the pixel value of color images (RGB24) with resolution of 320 x 240 pixels. From the documentation, I know that the images will have 3 bytes per pixel, and the image buffer will be 960 by 240 bytes in size. Therefore, I assume that Red plane is located at pixel 0 to 319; Green plane is at pixel 320 to 639; Blue plane is at pixel 640 to 959. Below is the example code that I wrote to extract Blue plane pixel value.

For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To 3 * ICImagingControl1.ImageWidth - 1
If x = 250 + 321 + 321 And y = 40 Then
Text2.Text = Text2.Text & ImageData(x, y) & vbCrLf
End If
Next x
Next y

My problem is the pixel value seems to be varied from what I got from other painting software. [image attached] For example, at pixel [250, 40], I suppose to get RGB(255, 143, 102) but I got RGB(110, 121, 102) instead. For your information, I assume Red value is at pixel [250,40], Green value is at pixel [250+321, 40] and Blue value is at pixel [250+321+321, 40].

It is very important for me to indentify the pixel value for each of the plane for color classification. Could you please explain how am I suppose to extract the RGB value from each of RGB plane? I guess I have used the wrong way :)

Thank you very much.

Best regards,
yklam

Stefan Geissler
August 4, 2003, 13:26:13
Hello Yklam,

the color parts of the pixels in the memory are directly in sequence. The colors components of the fist pixel are accessible as follows:
blue = pixel(0,0)
red = pixel(1,0)
green = pixell(2,0)

The first index is the line, the second index is the column.

yklam
August 5, 2003, 09:10:00
Hello,

I suppose the first index is the column (x), and the second index is the row (y). As for color image with resolution 320 x 240 pixels, width = 320*3 and height = 240. From here, in order to get pixel value at pixel(x, y) = pixel(250, 40), the color components:

blue = ImageData(250*3, 40)
red = ImageData(250*3+1, 40)
green = ImageData(250*3+2, 40)

The following is the example code:

Private Sub cmdprocess_Click()
Dim ImageData As Variant
Dim x As Integer, y As Integer

ICImagingControl1.MemorySnapImage
ImageData = ICImagingControl1.MemoryGetImageData
For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To 3 * ICImagingControl1.ImageWidth - 1
If x = 250 * 3 And y = 40 Then
Text5.Text = Text5.Text & "[R,G,B] = " & "[" & ImageData(x + 1, y) & ", " & ImageData(x + 2, y) & ", " & ImageData(x, y) & "]" & vbCrLf
End If
Next x
Next y
ICImagingControl1.MemoryReleaseImageData ImageData

End Sub

I found that the color components value are still varied from what I expected. As for example, at pixel(0,0) [please refer to pool2.jpg attached in last post], it should be green in color with value around RGB(144,169,142). However, the program output gives

blue = ImageData(0,0) = 255
red = ImageData(1,0) = 255
green = ImageData(2,0) = 255

I thought it was the problem of brightness but it gives me blue=178, red=178; green=178 after I reduced the brightness from 64 to 44. May I know did I interpret your explanation wrongly? Orelse, what is the reason that causing the color components to be varied so much from the expected one? For your information, I am using Logitech QuickCam Pro 4000. Thank you very much.

Best regards,
yklam

Stefan Geissler
August 6, 2003, 08:42:52
I did an error. The colors are save as BGR, means Bue, Green and Red. I wrote the wrong sequence. Also the images are saved bottom up. To get the colors at as specified pixel position, you need to code following:
blue = ImageData(250*3, ICImagingControl1.ImageHeight - 40)
green = ImageData(250*3+1,ICImagingControl1.ImageHeight- 40)
red = ImageData(250*3+2, ICImagingControl1.ImageHeight - 40)
This should work. If not, please send your sample project as zipped file to support@imagingcontrol.com.

yklam
August 6, 2003, 09:54:52
Hello,

Problem is solved. Thanks for help.

Best regards,
yklam