# Is the mean of visible color in CIELab color space can be non visible color?

I am converting color from RGB to CIELab to train a GMM. When I get back the mean of clusters of the GMM I have sometimes negatives values in RGB space. I was wondering if the mean of only visible color can be non visible color ? Therefore I was also wondering if the visual color of CIELab forms a convex shape.

EDIT: I'm using Expectation-Minimization of OpenCV to train the Gaussian Mixture Model.

-
It sounds like your colors are out of gamut. Which RGB color space are you working in? –  Emre Feb 5 '13 at 6:31
@Emre I guess it's the ISO RGB, where in normalized, (1,1,1) is white and (0,0,0) is black. I think I'm out of gamut but how can it be possible ? –  Seltymar Feb 5 '13 at 7:11
How did you convert to and from L*a*b* and RGB? –  Emre Feb 5 '13 at 7:55
@Emre I took the algorithm from this site easyrgb.com/index.php?X=MATH. I converted RGB to XYZ then XYZ to CIEL*a*b*. –  Seltymar Feb 5 '13 at 8:17
add comment

## 1 Answer

You are implicitly using sRGB, a small color space. You might like to try using scRGB, a similar color space that allows such values.

The average of visible colors should also be visible, however the calculation should be performed in a perceptual color space for the result to be more meaningful; L*a*b* is better than sRGB.

Another question to ponder is whether the centers make sense in L*a*b*. Perhaps you have a bug?

-
Ok, I see that in fact, sRGB is very a small part of the visible color. But as all colors are taken in sRGB space, even after converting in L*a*b*, the mean should stay in the subset define by sRGB, right ? I am not sure as it is a gaussian. It can also come from a bug. –  Seltymar Feb 5 '13 at 9:11
I think sRGB gamut in L*a*b is a non-convex shape, hence the line connecting two points can lay partly outside of the shape including its centroid (the color average). The resulting color can be theoretically out of sRGB gamut. You can make use larger RGB space (e.g. scRGB as Emre mentioned) or make use of some gamut mapping technique. –  Libor Feb 7 '13 at 16:26
@Libor thank you. That sounds logic. I will try with the scRGB space. –  Seltymar Feb 8 '13 at 0:29
add comment