opencv计算图像亮度调节_【OpenCV学习】图像亮度、对比度调节(伽马校正)-阿里云开发者社区...

【OpenCV学习】图像亮度、对比度调节(伽马校正)

老朱教授

2017-11-26

2164浏览量

简介:

#include "cv.h"

#include "highgui.h"

#include

int ImageAdjust(IplImage *src,IplImage *dst,

double low,double high, //x direction

double bottom,double top, //y direction

double gamma);

int main(void)

{

char *filename="lena.jpg";

IplImage *dst,*src = /blog.armyourlife.info/cvLoadImage(filename,0);

if(!src)

{

printf("Couldn't seem to Open %s, sorry/n",filename);

return -1;

}

cvNamedWindow( "src", 1 );

cvNamedWindow( "result", 1 );

// Image adjust

dst = cvCloneImage(src);

// 输入参数 [0,0.5] 和 [0.5,1], gamma=1

if( ImageAdjust( src, dst, 0, 0.5, 0.5, 1, 1)!=0)

return -1;

cvShowImage( "src", src );

cvShowImage( "result", dst );

cvWaitKey(0);

cvDestroyWindow("src");

cvDestroyWindow("result");

cvReleaseImage( &src );

cvReleaseImage( &dst );

return 0;

}

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;

}

本文转自gnuhpc博客园博客,原文链接:http://www.cnblogs.com/gnuhpc/archive/2012/10/13/2722909.html,如需转载请自行联系原作者

计算机视觉

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:

oAf2l2y9Or8QM0mzgzAAAAABJRU5ErkJgggAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值