-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_modify_im_contrast_brightness.cpp
More file actions
49 lines (41 loc) · 1.46 KB
/
05_modify_im_contrast_brightness.cpp
File metadata and controls
49 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by varora on 22/04/24.
//
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
// NOT "using namespace std;" here, to avoid collisions between the beta variable and std::beta in c++17
using std::cin;
using std::cout;
using std::endl;
using namespace cv;
int main( int argc, char** argv ) {
CommandLineParser parser(argc, argv, "{@input | ims/sample.jpg | input image}");
Mat image = imread(samples::findFile(parser.get<String>("@input")));
if (image.empty()) {
cout << "Could not open or find the image!\n" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
Mat new_image = Mat::zeros(image.size(), image.type());
double alpha = 1.0; /*< Simple contrast control */
int beta = 0; /*< Simple brightness control */
cout << " Basic Linear Transforms " << endl;
cout << "-------------------------" << endl;
cout << "* Enter the alpha value [1.0-3.0]: ";
cin >> alpha;
cout << "* Enter the beta value [0-100]: ";
cin >> beta;
for (int y = 0; y < image.rows; y++) {
for (int x = 0; x < image.cols; x++) {
for (int c = 0; c < image.channels(); c++) {
new_image.at<Vec3b>(y, x)[c] =
saturate_cast<uchar>(alpha * image.at<Vec3b>(y, x)[c] + beta);
}
}
}
imshow("Original Image", image);
imshow("New Image", new_image);
waitKey();
return 0;
}