views:

772

answers:

4

how can I see the color space of my image with openCV ?

I would like to be sure it is RGB, before to convert to another one using cvCvtColor() function

thanks

+3  A: 

Unfortunately, OpenCV doesn't provide any sort of indication as to the color space in the IplImage structure, so if you blindly pick up an IplImage from somewhere there is just no way to know how it was encoded. Furthermore, no algorithm can definitively tell you if an image should be interpreted as HSV vs. RGB - it's all just a bunch of bytes to the machine (should this be HSV or RGB?). I recommend you wrap your IplImages in another struct (or even a C++ class with templates!) to help you keep track of this information. If you're really desperate and you're dealing only with a certain type of images (outdoor scenes, offices, faces, etc.) you could try computing some statistics on your images (e.g. build histogram statistics for natural RGB images and some for natural HSV images), and then try to classify your totally unknown image by comparing which color space your image is closer to.

--Boatzart

Boatzart
thanks, so these pictures are taken by a smart phone using google android. I supposed they are RGB images, is that correct ? RGB is the most common color space right ?thanks
Patrick
Again, there's really no way to tell without actually displaying the images, but I think that RGB is a pretty safe assumption - it's what most people think of when they talk about a three channel color space. I would be pretty surprised if it was anything else.
Boatzart
A: 

Well... perhaps the color space is not RGB but BGR.

txandi
A: 

The IplImage struct has a field named colorModel consisting of 4 chars. Unfortunately, OpenCV ignores this field. But you can use this field to keep track of different color models.

f3lix
A: 

txandi makes an interesting point. OpenCV has a BGR colorspace which is used by default. This is similar to the RGB colorspace except that the B and R channels are physically switched in the image. If the physical channel ordering is important to you, you will need to convert your image with this function: cvCvtColor(defaultBGR, imageRGB, CV_BGR2RGB).

Oliver