码迷,mamicode.com
首页 > 其他好文 > 详细

《Gamma correct》

时间:2017-06-25 20:23:53      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:方向   char   transform   data   src   err   char*   otto   correct   

int ImageAdjust(IplImage* src, IplImage* dst,
double low, double high, // X方向:low and high are the intensities of src
double bottom, double top, // Y方向:mapped to bottom and top of dst
double gamma )
{
double low2 = low*255;
double high2 = high*255;
double bottom2 = bottom*255;
double top2 = top*255;
double err_in = high2 - low2;
double err_out = top2 - bottom2;
int x,y;
double val;
if(low<0 && low>1 && high <0 && high>1&&
bottom<0 && bottom>1 && top<0 && top>1 && low>high)
return -1;
// intensity transform
for( y = 0; y < src->height; y++)
{
for (x = 0; x < src->width; x++)
{
val = ((uchar*)(src->imageData + src->widthStep*y))[x];
val=pow((val - low2)/err_in, gamma)*err_out+bottom2;
if(val>255)
val=255;
if(val<0)
val=0; // Make sure src is in the range [low,high]
((uchar*)(dst->imageData + dst->widthStep*y))[x] = (uchar) val;
}
}
return 0;
}

《Gamma correct》

标签:方向   char   transform   data   src   err   char*   otto   correct   

原文地址:http://www.cnblogs.com/DeanWang/p/7077665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!