-
Notifications
You must be signed in to change notification settings - Fork 12
/
bgr_greyscale_conversion.cpp
34 lines (29 loc) · 1.01 KB
/
bgr_greyscale_conversion.cpp
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
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char **argv){
Mat img1;
img1 = imread(argv[1], CV_LOAD_IMAGE_COLOR);
Mat img2(img1.rows, img1.cols, CV_8UC1, Scalar(0));
Mat img3(img1.rows, img1.cols, CV_8UC1, Scalar(0));
int i, j;
for(i = 0; i < img1.rows; i++){
for(j = 0; j < img1.cols; j++){
img2.at<uchar>(i, j) = (img1.at<Vec3b>(i, j)[0] + img1.at<Vec3b>(i, j)[1] + img1.at<Vec3b>(i, j)[2]) / 3;
}
}
for(i = 0; i < img1.rows; i++){
for(j = 0; j < img1.cols; j++){
img3.at<uchar>(i, j) = 0.11*img1.at<Vec3b>(i, j)[0] + 0.59*img1.at<Vec3b>(i, j)[1] + 0.3*img1.at<Vec3b>(i, j)[2];
}
}
namedWindow("Normal", WINDOW_AUTOSIZE);
imshow("Normal", img1);
namedWindow("Average", WINDOW_AUTOSIZE);
imshow("Average", img2);
namedWindow("Weighted Average", WINDOW_AUTOSIZE);
imshow("Weighted Average", img3);
waitKey(0);
return 0;
}