<< return to Pixycam.com

Question about ColorLUT generate function

Hello
I would be thankful if You could tell me how this function works. Maybe You used some descriptions which are on some websites? Can You share me these description? I understand only what map and mean functions do.
Thank You

int ColorLUT::generate(ColorModel *model, const Frame8 &frame, const RectA &region)
{
    Fpoint meanVal;
    float angle, pangle, pslope, meanSat;
    float yi, istep, s, xsat, sat;
    int result;

    m_hpixels = (HuePixel *)maxMalloc(sizeof(HuePixel)*CL_HPIXEL_MAX_SIZE, &m_hpixelSize);
    if (m_hpixels==NULL)
        return -1; // not enough memory

    m_hpixelSize /= sizeof(HuePixel);

    map(frame, region);
    mean(&meanVal);
    angle = atan2(meanVal.m_y, meanVal.m_x);
    Fpoint uvec(cos(angle), sin(angle));

    Line hueLine(tan(angle), 0.0);

    pangle = angle + PI/2; // perpendicular angle
    pslope = tan(pangle); // perpendicular slope
    Line pLine(pslope, meanVal.m_y - pslope*meanVal.m_x); // perpendicular line through mean

    // upper hue line
    istep = fabs(m_iterateStep/uvec.m_x);
    yi = iterate(hueLine, istep);
    yi += fabs(m_hueTol*yi); // extend
    model->m_hue[0].m_yi = yi;
    model->m_hue[0].m_slope = hueLine.m_slope;

    // lower hue line
    yi = iterate(hueLine, -istep);
    yi -= fabs(m_hueTol*yi); // extend
    model->m_hue[1].m_yi = yi;
    model->m_hue[1].m_slope = hueLine.m_slope;

    // inner sat line
    s = sign(uvec.m_y);
    istep = s*fabs(m_iterateStep/cos(pangle));
    yi = iterate(pLine, -istep);
    yi -= s*fabs(m_satTol*(yi-pLine.m_yi)); // extend
    xsat = yi/(hueLine.m_slope-pslope); // x value where inner sat line crosses hue line
    Fpoint minsatVec(xsat, xsat*hueLine.m_slope); // vector going to inner sat line
    sat = dot(uvec, minsatVec); // length of line
    meanSat = dot(uvec, meanVal);
    if (sat < m_minSat) // if it's too short, we need to extend
    {
        minsatVec.m_x = uvec.m_x*m_minSat;
        minsatVec.m_y = uvec.m_y*m_minSat;
        yi = minsatVec.m_y - pslope*minsatVec.m_x;
    }
    model->m_sat[0].m_yi = yi;
    model->m_sat[0].m_slope = pslope;

    // outer sat line
    yi = iterate(pLine, istep);
    yi += s*fabs(m_maxSatRatio*m_satTol*(yi-pLine.m_yi)); // extend
    model->m_sat[1].m_yi = yi;
    model->m_sat[1].m_slope = pslope;

    // swap if outer sat line is greater than inner sat line
    // Arbitrary convention, but we need it to be consistent to test membership (checkBounds)
    if (model->m_sat[1].m_yi>model->m_sat[0].m_yi)
    {
        Line tmp = model->m_sat[0];
        model->m_sat[0] = model->m_sat[1];
        model->m_sat[1] = tmp;
    }

    free(m_hpixels);

    // calculate goodness
    result = (meanSat-m_minSat)*100/64 + 10; // 64 because it's half of our range
    if (result<0)
        result = 0;
    if (result>100)
        result = 100;

    return result;
}

Hello J B,
This looks like some of the older color signature code. This code is actually significantly different in the latest version. The technique is based on some methods that were developed at Charmed Labs and CMU. I’m sorry, but I don’t think this has been published in a paper anywhere.

Edward

Thank You for reply. Could You tell me which function is the newest to generate LUT and where can I found it (which file)?
JB

Hello J B,
Look in src/common/src/colorlut.cpp for the lut code. The ColorLUT::generateLUT() method is probably what you’re looking for.

Edward

Thank You. I can’t find Where do you call the ColorLUT::generateLUT() method. Could You show me?

And if You could tell which code for M0 core is the newest? Or maybe is it still the same?

Hello J B,
You should grab the latest source using the git tool:

This will guarantee you have the latest source.

To find where generateLUT() is called, use your favorite search tool. I like to use grep.

Edward