opencv hog.cpp中的gamma校正 [英] gamma correction in opencv hog.cpp

查看:370
本文介绍了opencv hog.cpp中的gamma校正的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解opencv中hog.cpp中伽马校正的代码,我浏览了一些链接 here 与opencv中的代码不匹配hog.cpp

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;

我从代码中理解的是,如果伽马校正为真,它会创建1x256的二维数组将计算数据的平方根。我试图调试遍历与此代码相关的所有文件,但dint理解。任何人都可以简单地告诉我们这里发生的事情。

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.

推荐答案

你所做的就是建立一个查找表;你知道传入的数据是字符,所以所有像素只能有0-255的值,所以如果你正在进行伽马校正,你会预先计算平方根。稍后将在每像素梯度计算中使用它。
稍后在computeGradients()中,你得到行指针:

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];

然后索引到查找表中以获取[-1 0 1]渐变的像素值:

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]]);
        }

这篇关于opencv hog.cpp中的gamma校正的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆