听说,将RGB图像归一化之后,可以消除部分光照影响,于是在没有找着现成的之后试着写了个,发现它并不能解决我的问题, 处理之后的视觉效果比较差还,像素之间显得那么不和谐。
现将源码公布,请大家多多指导。
// 将BGR颜色归一化,消除线性光照影响
bool colorNormal(Mat& img)
{
if (img.channels() != 3)
{
return false;
}
int nl= img.rows; // number of lines
int nc= img.cols ; // number of columns
// is it a continous image?
if (img.isContinuous())
{
// then no padded pixels
nc= nc*nl;
nl= 1; // it is now a 1D array
}
double bgrSum;
// for all pixels
for (int j=0; j<nl; j++)
{
// pointer to first column of line j
uchar* data= img.ptr(j);
for (int i=0; i<nc; i++)
{
// process each pixel --------
bgrSum= 255.0/(1 +data[0] +data[1] +data[2]);
data[0] *=bgrSum;
data[1] *=bgrSum;
data[2] *=bgrSum;
data +=3;
}
}
return true;
}