图像亮度、对比度调节(伽马校正)
2016-03-21 19:30
393 查看
【OpenCV学习】图像亮度、对比度调节(伽马校正)
作者:gnuhpc出处:http://www.cnblogs.com/gnuhpc/
#include "cv.h" #include "highgui.h" #include <stdio.h> 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/
相关文章推荐
- 敏捷完工与公布检查
- IOS 网络浅析-(八 NSURLSession简介)
- 5-25 念数字 (15分) c语言
- SQL中存储过程和函数的区别
- thttpd服务器移植到ARM Linux教程
- 1033. 旧键盘打字(20)
- 动态规划(模型转换):uvaoj 1625 Color Length
- hdu 1151 Air Raid DAG最小路径覆盖
- ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.10.210' (111) 解决方法
- java不同安装包的安装方法(rpm,bin,tar)
- Navicat for Mysql注冊码
- 读后感——《构建之法》第1.2.3章
- 复利计算4.0
- 《Linux内核分析与设计》读书笔记二
- UITableView,UICollectionView和CoreData完美结合进行增删改操作,如何导入大量数据,如何利用NSEntityMigrationPol
- plsql developer 查看执行计划
- 50国内外最优秀的C/C++源代码网站分享
- 61.iOS 保持界面流畅的技巧
- MySQL 支持远程登陆设置
- 添加右键启动快捷键