[原创]opencv图像亮度/对比度调整实验
2015-09-13 13:14
441 查看
[原创]opencv图像亮度/对比度调整实验
Author: chadMail: linczone@163.com
亮度和对比度调整实验
两种常用的点过程(即点算子),是用常数对点进行 乘法 和 加法 运算:
g(x) = A*f(x) + B
两个参数 A和 B 一般称作 增益 和 偏置 参数。我们往往用这两个参数来分别控制 对比度 和 亮度 。
你可以把 f(x) 看成源图像像素,把 g(x) 看成输出图像像素。这样一来,上面的式子就能写得更清楚些:
g(i,j) = A*f(i,j) + B
其中, i 和 j 表示像素位于 第i行 和 第j列 。
降低亮度时保证g(x) < f(x), 增加亮度时g(x) > f(x) .
源码位置:
opencv-3.0.0-rc1/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp
源码如下 :
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; double alpha; /**< 控制对比度 */ int beta; /**< 控制亮度 */ int main( int argc, char** argv ) { /// 读入用户提供的图像 Mat new_image = Mat::zeros( image.size(), image.type() ); /// 初始化 cout << "-------------------------" << endl; cout << "* Enter the alpha value [1.0-3.0]: "; cin >> alpha; cout << "* Enter the beta value [0-100]: "; cin >> beta; new_image(i,j) = alpha*image(i,j) + beta for( int y = 0; y < image.rows; y++ ) { for( int x = 0; x < image.cols; x++ ) { for( int c = 0; c < 3; c++ ) { new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta ); } } } /// 创建窗口 namedWindow("Original Image", 1); namedWindow("New Image", 1); /// 显示图像 imshow("Original Image", image); imshow("New Image", new_image); /// 等待用户按键 waitKey(); return 0; }
实验结果如下:
相关文章推荐
- linux free命令用法以及解释
- CentOS7中文输入法,拼音输入法
- Shell: nohup守护进程化
- Nginx Location配置总结
- bash shell数组
- 虚拟机安装 centos7 注意事项
- 用花生壳怎样发布网站
- PX4源码开发人员文档(一)——软件架构
- linux shell — 1.命令的执行方式、man page 和关机
- linux软RAID
- 门户网站
- linux学习一
- linux如何再次运行那个很久之前曾用过的命令---历史命令搜索方法
- grep及正则表达式
- Shell公共函数:/etc/init.d/functions详解
- sed基本用法
- 算法思想:维护而非重新计算
- 分布式缓存GemFire架构介绍
- Hadoop权威指南第4版第7章Anatomy of a MapReduce Job Run
- kick start 无人值守安装Linux