Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDColor : about converting RGB to CIEL*a*b* #9

Open
AbsurdePhoton opened this issue Oct 14, 2020 · 0 comments
Open

EDColor : about converting RGB to CIEL*a*b* #9

AbsurdePhoton opened this issue Oct 14, 2020 · 0 comments

Comments

@AbsurdePhoton
Copy link

AbsurdePhoton commented Oct 14, 2020

Hi,

nice job done here, I tried your library and it works pretty well (I only used EDColor which interested me more).

Looking at the code, there's something maybe you're not aware of.
When converting RGB to XYZ space, RGB values have to be linear (gamma corrected).
So like in the test example, feeding the algorithm with an image directly read from a file is a bit incorrect. I added my own function to get lineared RGB and the detection is better !

If you want to try it yourself, here is my function to convert RGB to linear :

void EDColor::RGBtoLinear(const double &R, const double &G, const double &B, double &r, double &g, double &b, const bool &fast) // Apply linear RGB gamma correction
{
    if (fast) {
        r = 0.012522878 * R + 0.682171111 * R * R + 0.305306011 * R * R * R;
        g = 0.012522878 * G + 0.682171111 * G * G + 0.305306011 * G * G * G;
        b = 0.012522878 * B + 0.682171111 * B * B + 0.305306011 * B * B * B;
    }
    else {
        // Gamma correction - conversion to linear space - source http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
        // most correct approximation but it is SLOW
        if (R > 0.04045)
            r = pow((R + 0.055) / 1.055, 2.4);
        else
            r = R / 12.92;
        if (G > 0.04045)
            g = pow((G + 0.055) / 1.055, 2.4);
        else
            g = G / 12.92;
        if (B > 0.04045)
            b = pow((B + 0.055) / 1.055, 2.4);
        else
            b = B / 12.92;
    }
}

In EDColor.cpp, function MyRGB2LabFast() - compute red, green and blue like this :

...
for (int i = 0; i<width*height; i++) {
        R = redImg[i] / 255.0;
        G = greenImg[i] / 255.0;
        B = blueImg[i] / 255.0;
        RGBtoLinear(R, G, B, red, green, blue, true);
        ...

Regards,
AbsurdePhoton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant