#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** crgv) {
Mat src, dst;
src = imread("C:/Users/AA/Desktop/myc++/1.jpg");
imshow("input", src);
int height = src.rows;
int width = src.cols;
int channl = src.channels();
float w = 1.6;
float ba = -30;
dst = Mat::zeros(src.size(), src.type());
Mat m1;
src.convertTo(m1, CV_32F);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (channl == 3) {
float b = m1.at<Vec3f>(row, col)[0];
float g = m1.at<Vec3f>(row, col)[1];
float r = m1.at<Vec3f>(row, col)[2];
dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>( b*w + ba);
dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(g*w + ba);
dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(r*w + ba);
}
else {
float v = src.at<uchar>(row, col);
dst.at<char>(row, col) = saturate_cast<uchar>(v*w + ba);
}
}
}
imshow("output", dst);
waitKey(0);
return 0;
}
```cpp
在这里插入代码片