-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorHistEqaulization.cpp
55 lines (40 loc) · 1.24 KB
/
ColorHistEqaulization.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//header files
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
//using namespaces
using namespace cv;
using namespace std;
int main()
{
//open and read the image
Mat img = imread("test.jpg", CV_LOAD_IMAGE_COLOR);
//if unsuccessful, exit the program
if(img.empty())
{
cout<<"Image cannot be loaded"<<endl;
}
vector<Mat> channels;
Mat img_hist_equalized;
//change the color of image from BGR to YCrCb
cvtColor(img, img_hist_equalized, CV_BGR2YCrCb);
//split the image into channels
split(img_hist_equalized, channels);
//equalize histogram on the 1st channel (Y)
equalizeHist(channels[0], channels[0]);
//merge 3 channels including the modified 1st channel into one image
merge(channels, img_hist_equalized);
//change the color of the image from YCrCb to BGR format (to dispaly image properly)
cvtColor(img_hist_equalized, img_hist_equalized, CV_YCrCb2BGR);
//create Windows
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
namedWindow("Histogram Equalized", CV_WINDOW_AUTOSIZE);
//show th image
imshow("Original Image", img);
imshow("Histogram Equalized", img_hist_equalized);
//wait for key press
waitKey(0);
//destroy all open Windows
destroyAllWindows();
return 0;
}