【OpenCV学习笔记】之五 RGB图像归一化处理函数,消除线性变化的光照影响

来源:互联网 发布:李小璐淘宝店名 编辑:程序博客网 时间:2024/05/17 23:50

       听说,将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 pixelsnc= 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 juchar* 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;}


原创粉丝点击