Given two RGB pixels, with components R1,G1,B1 and R2,G2,B2, how would be such function f(R,G,B) -> X for which a comparison f(R1,G1,B1) < f(R2,G2,B2) would be noise robust and have a reasonable interpretation ?
There are many ways to project RGB onto a single value. The simplest is probably the HSV (or HSL) model. The Hue value would have "a reasonable interpretation". See https://en.wikipedia.org/wiki/HSL_and_HSV
Although the Hue value of the HSL/HSV model would be a good metric for comparing in-between colors, the Hue values for Grayscale pixels (R=G=B) is undefined and therefore it wouldn't make sense to compare a "colored" pixel against a pure grayscale pixel.
Often people will first convert the RGB values to the Lab colorspace and then measure Euclidean distance in the 3-dimensional Lab colorspace. I have seen claims the Lab colorspace tries to model human interpretation of color and not machine interpretation of color (like RGB), so the idea is that the distance between Lab vectors is more meaningful than the distance between RGB vectors. I don't have a reference for this other than the Wikipedia article so I'm not sure of the exact science behind it.
Mr Neto, in your question you have stated that you want to perform some mathematical function by feeding the pixel values of red, blue and green as input variables. As Mr Taylor and Mr Keffalas have said it is better to convert your RGB values of a pixel into either device dependent or device independent color space components and use those color components for any further processes. But if you want to compare RGB values of a pixel with a reference gray scale image means, surely you have to convert your RGB image into gray scale image and then compare it with your reference gray scale image. If you are still in need of clarification , I request you to broaden your question statement and I will surely say you.
This question could be detailed as the following : "Given two (2) RGB pixel values, how one could obtain a robust metric that allows for the usage of Equality/Inequality operators (e.g : greater than, lower than, equal, etc ...) as it would be done with a Grayscale pixel (eg: if P1 > P2 or P1 < P2) ? "
So as there are many color spaces, which would be the most meaningful for using with both RGB and grayscale pixels as well, and which would be the most noise robust model for using with noisy RGB values ?
Hi, Jorcy. A good color space to computing color diference is the CIELab. There is a report on http://www.cie.co.at/index.php/index.php?i_ca_id=252 with a lot of equation used for that.
It will be good if you can provide more information. I don't really know what do you mean with "comparing/discerning two RGB pixels values?" Comparing in terms of what exactly? For instance, you could be comparing pixel values in terms of perceived color differences, then in such case I would recommend to use a measure such as Delta E 2000 or similar color difference formula (cf. link below).
If this is not helpful, please provide more information. Because comparing RGB values depends on the application and the purpose of the end result.
Basically : "I need to extract some information between two (2) RGB pixel values as a boolean value". The most reasonable method I percieved was to apply some fuction/transformation over the RGB coordinates, and then compare the result of this fuction when applied to both pixels.
For a grayscale value, it is pretty imediate to determine, for example if one pixel has a higher intesity than another, and then extract a boolean value if P1 > P2 or P2 > P1. However, extracting the same infomation from a RGB without losing some relavance of the individual R, G, B values has shown istelf a non-trivial task.
The same boolean value may be also obtained by a function of three RGB pixels as well, but it still needs to output a single boolean value.
Also, having a human perception based influence like most of the colorimetry models is not mandatory in this case, as the result of this function is oriented to a machine learning application.
1. It seems like you want to know if a pixel has higher value than the other. However, if you do that in RGB images it will be something like comparing magnitudes of the RGB vectors or converting the image to gray scale using PCA or similar techniques (cf. link below).
2. If you want to know if the two colors are similar you can use Delta E 2000 as I told you before. Then, the boolean output is 1 if the colors are almost the same (Delta E 2000 lower than 2 or 3) and 0 otherwise.
I told you these two options because for me does not make sense or I don't see how to compute: "if a RGB values is bigger or smaller than the other".
I'll take a look in depth into these papers. Actually the Delta E 2000 is a quite new concept for me in this field. I'll also try using the color distance in the CIELab space and in other color spaces as well.
For sure. I was prety aware of the circular-based coordinates of the Hue component, and therefore also thought it wouldn't be suitable for comparisons in a metric basis ( a > b or a < b ). However i still think that a color information is somewhat needed and Value and Saturation only, wouldn't be suitable distinguishing in between colored pixels.
I'll also try on using Lp-norms ( https://en.wikipedia.org/wiki/Lp_space ) distance calculations in-between sequece of pixels in RGB and other linear coordinate spaces as well (e.g. : dist(P1,P2) < dist(P2,P3) ).