Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

ImageToArray for color image?

Solved!
Go to solution

I am using Labview 8.2 and NI vision

 

there is an NI example called imagetoarray which uses the function of ImagtoArray.vi; in the example, the souce image is one monochrome bmp image, and the resulting single value for each pixel, I assume, should be the intensity/brightness of each pixel, isn'it?  however when I load an colorful bmp/jpg file into this example, I would expect an error message saying "wrong type image", but  it goes through, and show single value for each pixel too. then what does this pixel value here stand for? the unsigned 32 bit interg? what about each individual color?

 

my second question is related to the function of GetColorPixelValue.vi. I am trying to use this function to extract a fixed coordinate pixel's color value, the coordiate is pre-set. when I use this function to analyze the jpg image I used above, it gives an error message " worng image type", then I tried one bmp image , it also shows " worng image type". what is wrong with my operation? should it be able to handle a bmp/jpg image? does anyone has some suggetion?

 

regards,

t.z

 

Message Edited by bigworld on 04-02-2010 05:30 PM
0 Kudos
Message 1 of 8
(4,245 Views)
Solution
Accepted by bigworld

I expect you are facing this trouble on account of the "Image Type" you create when running "IMAQ Create".

The NI example you have mentioned creates an 8-bits image.

The GetColorPixelValue requires an RGB or HSL image, see the Help topic for this VI.

Regards, Guenter

0 Kudos
Message 2 of 8
(4,233 Views)

Hey t.z.

 

In terms of the root cause of the behavior you are seeing, Guenter it probably right. The issues you are seeing is likely due to the type of buffer you are creating with the IMAQ Create VI. First, are you using an example program called imagetoarray or are you using the IMAQ ImageToArray VI that you would find on your functions palette. If it is an example program, would you mind linking it? If you are using the VI, the VI only works with 8-bit, 16-bit, or floating point images and not color images. If you are working with color images, there is an IMAQ ColorImageToArray VI that you might want to use. 

 

In terms of 'type' the errors you are getting are referring to the type of image buffer (RGB, 8-bit, 16-bit, etc.) and not file type (jpeg, bmp, png, etc.). So, if I had to guess, I would guess that you are bringing your image into LabVIEW as a image type other than and RGB. This would explain the single value with the IMAQ ImageToArry and the image type errors with the GetColorPixelValue VI.

Hope this helps.
-Ben

WaterlooLabs
0 Kudos
Message 3 of 8
(4,207 Views)

Hi, Guenter & Bcho,

  thanks for the reply. I think you are right. after I set the image type in creatimage.vi to RGB 32, it goes through. so this is normal mistake for a greenhand.^-^. but I have run into another 2 questions. if I chose one pixle whose RGB value showing below the image as  (65,86,117), and on the funciton of ColorImageToArray, the output (U32) shows a unsigned integer 5400969. I think the original stored data must be like (11001100,10101010,01010101,00000000),the above number may not be accurate, just for illustration, but the last value has to be zero since there is no alpha in this image. then when the computer processing , it treat them as one number like (11001100101010100101010100000000), and convert to 5400969. am I right? but if I want to save the value like (65,86,117), is there an VI I could use?

 

2nd, the same image , I set as RGB(32) , then later I set as HSL(32), both give me results. I know these 2 formats are equal because they can covert between each other. but I wonder that this sepcific picture should be saved in only one format. then how does it get throght in both format?

 

thanks,

t.z. 

Message Edited by bigworld on 04-05-2010 12:39 PM
0 Kudos
Message 4 of 8
(4,201 Views)

Hi t.z.

You can take from IMAQ IntergerToColorValue, that 5400969 = (R=83, G=240, B=41), all values are decimals.

The U32 in NI Vision uses to three low bytes to represent a RGB value.

 

I do not understand your second question: Maybe you might want to post a VI that makes clear what you are doing, please?

Regards, Guenter

0 Kudos
Message 5 of 8
(4,193 Views)

Hi, Guenter

 thanks for the reply, the intergertocolorvalue function works. and about "The U32 in NI Vision uses to three low bytes to represent a RGB value."  here, "the three low bytes", did you mean Labview throw away the forth byte which is supposed to be "alpha" ? could you give a little more detail?

 

about my 2nd question,   I mean when I creat an image , I could set "the image type" as RGB(32) , or HSL(32), but when I  read one specific picture by either format,  it get through, no error. ( these 2 formats are equal because they can covert between each other). but for this sepcific picture, it should be saved in only one format, RGB or HSL. then how does it get throgh by both format? did Labview do an automatic convertion when labview open it?

 

regards,

t.z.

Message Edited by bigworld on 04-05-2010 04:26 PM
Message Edited by bigworld on 04-05-2010 04:28 PM
0 Kudos
Message 6 of 8
(4,185 Views)

Hi t.z.

BTW, do you know the Vision Concepts Help?

The topic "Image Types" mentions, that NI Vision does not use the Alpha Channel.

 

VisionConceptsHelp.png  

 

The topic "Color Spaces" should handle your second question.  (I do not want to do any copy and paste here.)

You will find the Vision Consepts Help in the NI Vision Documentation.

Hope this helps, Guenter

Message 7 of 8
(4,157 Views)

Hi, Guenter,

  I download it and it helps.

thanks. 

 

t.z.

0 Kudos
Message 8 of 8
(4,134 Views)