I am implementing a classifier that is capable of recognizing vehicle color, and I am using the 3D color histograms of the region of interest as a feature vector, computed using openCV's method, calcHist()
. Specifically, to calculate the histograms, I use hist = cv.calcHist([hsv_image], [0, 1, 2], None, (8,8,8), [0, 180, 0, 256, 0, 256])
. With these parameters, I got, by doing the flatten()
of the histogram, a feature vector of 8x8x8 = 512, and with these feature vectors the classifier works pretty well, but I'm looking to further improve the accuracy of my model. So, what I would like to know is if there is any correlation between the number of bins and the range of color channel values, so that I can choose the best number of bins possible.

- 56
- 7
1 Answers
I'd suggest if you want to improve accuracy, perhaps try a perceptually accurate colorspace — and HSV isn't one. As color is not "real", and only a perception, it would follow that using a perceptually accurate appearance model is a best practice for your application.
Perceptual Appearance Models
CIECAM02, CIECAM16, Jzazbz are pretty much state of the art, and there is ZCAM for HDR imagery, and also image appearance models such as iCAM. These might not be available in a library for OpenCV, but most aren't that difficult to implement.
CIELAB
A simpler model is CIELAB which is part of OpenCV, and is a better choice than HSV or HSL, particularly if you are goal is to judge or select colors in a manner similar to human perception.
L*a*b* breaks the colors down based on human perception and the opponent process of vision. The channels are perceptual lightness, L* as a value from 0 to 100, and a* and b* which encode red/green and blue/yellow respectively, and are each nominally -128 to 127 if using signed 8bit integers.
LAB is a 3D Cartesian space. To determine the color difference, it is simply the euclidian distance between two colors, in other words, the square root of the sum of the squared differences, so:
∆ = ((L*1 - L*2)2 + (a1 - a2)2 + (b1 - b2)2 )0.5
Polar Version
CIELAB is also available with polar coordinates, LCh, for Lightness, Chroma, and hue.
Saturation is not available with LAB, only Chroma. The other color appearance models I mentioned above do have a saturation correlate, as well as brightness in addition to lightness. (Brightness being a different perception than lightness/darkness).

- 3,952
- 1
- 9
- 24
-
Thank you very much for the answer. Hence, can I use this color space to build a flatten 3D histogram to use as feature vector? – simone campisi Sep 12 '21 at 08:08
-
Hi @simone campisi, yes, though I think you might want to use the polar coordinates version (LCh, lightness, chroma, hue)... I answered another question last night and included the code to do so: https://stackoverflow.com/a/69148028/10315269 – Myndex Sep 12 '21 at 15:05
-
But using the polar coordinates I get the coordinate of a single color, right? In my pictures i have the vehicle located in a background, so there are others colors around the vehicle. So, for this reason I thought that was better to use the distribution of the colors as features vectors. – simone campisi Sep 13 '21 at 05:49
-
@simonecampisi Yes, for LAB the coordinates are L* a* b*, and for LCh the coordinates are L* C* h. An advantage with LCh is the ability to identify a hue "angle" separately from "colorfulness" as defined by C* chroma. With the a* b* cartesian coordinates, the meaning is more abstract. – Myndex Sep 14 '21 at 02:27