opencv笔记七(调整图像亮度和对比度)

原理公式:

α可以拉开像素之间的差距,所以增强了对比度,β提高整体亮度。

 

小知识点:

再次参考:https://blog.csdn.net/qq_29540745/article/details/52517269

其中8U类型指代 u_int8_t ,它是平台无关的,在任何平台下,它都代表8位无符号数

 

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;

Mat t1, t2;
int main(int agrc, char** agrv) {
	t1 = imread("test1.jpg");
	if (!t1.data || !t1.data) {
		cout << "WRONG";
		return -1;
	}
	char *c2 = "bitwise";
	namedWindow(c2, 0);
	t1.copyTo(t2);
	double light = 1.5;
	int li = 30;
	for (int row = 0; row < t1.rows; row++) {
		for (int col = 0; col < t1.cols; col++) {
			t2.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(light*t1.at<Vec3b>(row, col)[0]+li);
			t2.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(light*t1.at<Vec3b>(row, col)[1] + li);
			t2.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(light*t1.at<Vec3b>(row, col)[2] + li);
		}
	}
	imshow("t1", t1);
	imshow(c2, t2);
	waitKey(0);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值