Opencv去除⾼光的算法--HighlightsRemoval
这篇⽇志主要是根据⽂章“实时单幅图⽚⾼光去除算法”(篇⼀)和“Real-time Specular Highlight Removal Using a Single Image -eccv-10-qingxiong-yang“(篇⼆)来写的,没有终于原⽂,原⽂在后⾯做的⼀些逼近⼯作或滤波⼯作我没有进⾏精确的处理,但是这是上述两⽚论⽂的基本原理。这两篇论⽂的最⼤不同在于后⾯最⼤漫反射⾊度的求法,两者从不同的⾓度进⾏的,但我更倾斜于第⼆种,因为篇⼀是参考篇⼆,其中难免借⽤了⼀些其的观点,⽽且我觉得篇⼆实现起来更符合图像处理的观点,当然篇⼀也有其合理之处。建议有兴趣的读者可以去看看,篇⼆在论坛⾥有得下载,或者去 下载,如要引⽤,请注明出处,代码如下:
int highlight_remove_Chi(IplImage* src,IplImage* dst,double Re)
曾子杀猪翻译{
int height=src->height;
int width=src->width;
调研心得>沧州美食int step=src->widthStep;
int i=0,j=0;
unsigned char R,G,B,MaxC;
double alpha,beta,alpha_r,alpha_g,alpha_b,beta_r,beta_g,beta_b,temp=0,realbeta=0,minalpha=0;
double gama,gama_r,gama_g,gama_b;
unsigned char* srcData;洋奶粉
unsigned char* dstData;
for (i=0;i<height;i++)
{
srcData=(unsigned char*)src->imageData+i*step;
dstData=(unsigned char*)dst->imageData+i*step;
for (j=0;j<width;j++)
跑成语{
R=srcData[j*3];
G=srcData[j*3+1];
B=srcData[j*3+2];
alpha_r=(double)R/(double)(R+G+B);
alpha_g=(double)G/(double)(R+G+B);
alpha_b=(double)B/(double)(R+G+B);
alpha=max(max(alpha_r,alpha_g),alpha_b);
MaxC=max(max(R,G),B);// compute the maximum of the rgb channels
minalpha=min(min(alpha_r,alpha_g),alpha_b);
beta_r=1-(alpha-alpha_r)/(3*alpha-1);
beta_g=1-(alpha-alpha_g)/(3*alpha-1);
beta_b=1-(alpha-alpha_b)/(3*alpha-1);
6542是什么药
手工彩纸beta=max(max(beta_r,beta_g),beta_b);//将beta当做漫反射系数,则有 // gama is ud to approximiate the beta
gama_r=(alpha_r-minalpha)/(1-3*minalpha);
gama_g=(alpha_g-minalpha)/(1-3*minalpha);
gama_b=(alpha_b-minalpha)/(1-3*minalpha);
gama=max(max(gama_r,gama_g),gama_b);
temp=(gama*(R+G+B)-MaxC)/(3*gama-1);
//beta=(alpha-minalpha)/(1-3*minalpha)+0.08;
//temp=(gama*(R+G+B)-MaxC)/(3*gama-1);
dstData[j*3]=R-(unsigned char)(temp+0.5);
dstData[j*3+1]=G-(unsigned char)(temp+0.5);
dstData[j*3+2]=B-(unsigned char)(temp+0.5);
}
}
return 1;
}
下⾯是⽤上述代码做的两组实验结果,第⼀副为原图,第⼆幅为去⾼光后的图⽚,效果⽐较明显。
但是该算法对具有⼤⾯积⾼光的图⽚,处理的效果很⼀般,很容易出现过处理或处理不⾜的情况。对这⽅⾯有兴趣的朋友,欢迎⼀起来讨论。
登时
另⼀个类似⽂章链接:。
去除光照⽅⾯总结的⽐较多的⼀个⽂章,链接