gamma correction in opencv hog.cpp

*爱你&永不变心* 提交于 2019-12-13 04:36:02

问题


I dont understand the code of the gamma correction in hog.cpp in opencv, i went through some links here which doesnt match with the code in opencv hog.cpp

Mat_<float> _lut(1, 256);

const float* lut = &_lut(0,0);

if( gammaCorrection )
    for( i = 0; i < 256; i++ )
        _lut(0,i) = std::sqrt((float)i);
else
    for( i = 0; i < 256; i++ )
        _lut(0,i) = (float)i;

All i understood from the code is it creates 2 dimensional array of 1x256, if gamma correction is true it will calculate the square root of data.I tried to debug going through all the files related to this code but dint understood. Can anyone briefly tell whats happening here.

Please help
Thanks in advance.


回答1:


All you're doing there is building a lookup table; you know the incoming data is chars, so all pixels can only have values from 0-255, so if you're doing gamma correction you precalculate the square-root. This gets used later on, inside the per-pixel gradient calculation. Later on in computeGradients(), you get the row pointer:

const uchar* imgPtr  = img.data + img.step*ymap[y];

Then index into the lookup table to get the pixel values for the [ -1 0 1 ] gradients:

        for( x = 0; x < width; x++ )
        {
            int x1 = xmap[x];

            dbuf[x] = (float)(lut[imgPtr[xmap[x+1]]] - lut[imgPtr[xmap[x-1]]]);
            dbuf[width + x] = (float)(lut[nextPtr[x1]] - lut[prevPtr[x1]]);
        }


来源:https://stackoverflow.com/questions/16593126/gamma-correction-in-opencv-hog-cpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!