公式:
G(X)=a*raw(X)+b
线性方程,改变图像的亮度
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main() {
Mat src;
src = imread("F:/test.jpg");
int width = src.cols;
int height = src.rows;
Mat dst;
dst = Mat::zeros(src.size(), src.type());
float alpha = 1.2;
float beta = 30;
Mat ml;
src.convertTo(ml, CV_32F);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (src.channels() == 3) {
float b = ml.at<Vec3f>(row, col)[0];
float g = ml.at<Vec3f>(row, col)[1];
float r = ml.at<Vec3f>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(b*alpha + beta);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(g*alpha + beta);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(r*alpha + beta);
}
}
}
imshow("点运算", dst);
waitKey(0);
return 0;
}