-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogramViewer.cpp
95 lines (68 loc) · 1.71 KB
/
histogramViewer.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "histogramViewer.hpp"
/***********************************/
//CONSTRUCTORS
HistogramViewer::HistogramViewer()
{
}
HistogramViewer::HistogramViewer(Mat inImage)
{
this->image = inImage;
}
/***********************************/
//SETTERS
void HistogramViewer::setImage(Mat inImage)
{
this->image=inImage;
}
void HistogramViewer::setHisto(Mat inHisto)
{
this->histo=inHisto;
}
void HistogramViewer::setNbBins(int inNbBins)
{
this->nbBins=inNbBins;
}
/***********************************/
//GETTERS
/***********************************/
//FUNCTIONS
void HistogramViewer::process()
{
HistogramProcessor myHisto;//Class to compute the histo
//Compute the histogram
myHisto.setImage(image);
myHisto.setNbBins(nbBins);
myHisto.process();
histo=myHisto.getHisto();
//Visualize the histogram
viewHisto();
}
void HistogramViewer::viewHisto()
{
visualizeHistogram(image,histo,nbBins);
}
void HistogramViewer::visualizeHistogram(const Mat& src, const Mat& hist, int nbins)
{
double maxVal=0;
minMaxLoc(hist, 0, &maxVal, 0, 0);
int scale = (600.0/nbins);
Mat histImg = Mat::zeros(180 , nbins*scale, CV_8UC3);
for( int h = 0; h < nbins; h++ )
{
float binVal = hist.at<float>(h, 0);
int intensity = cvRound(binVal*180/maxVal);
rectangle( histImg, Point(h*scale,180-intensity),
Point((h+1)*scale - 1, 180),
cv::Scalar(255,0,0),
CV_FILLED );
}
namedWindow( "Source", 1 );
imshow( "Source", src );
cv::startWindowThread();
namedWindow( "Hue Histogram", 1 );
imshow( "Hue Histogram", histImg );
waitKey();
cv::destroyAllWindows();
cv::waitKey(1);
return;
}