CihanTopal / ED_Lib

Implementations of edge (ED, EDColor, EDPF), line (EDLines), circle and low eccentric ellipse (EDCircles) detection algorithms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

AbsurdePhoton opened this issue · comments

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.