-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathallHistograms.cpp
76 lines (50 loc) · 2.31 KB
/
allHistograms.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
#include "final.h"
/************************************************
calcHistogram is the same impl for rgb and yuv
************************************************/
Mat globalHistogram(Mat src){
vector<Mat> planes;
split( src, planes );
int histSize = YUVsinglechannel; /* 32 */
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
Mat singleChannel, histogram;
/// Compute the histograms:
calcHist( &planes[0], 1, 0, Mat(), singleChannel, 1, &histSize, &histRange, uniform, accumulate );
histogram.push_back(singleChannel);
calcHist( &planes[1], 1, 0, Mat(), singleChannel, 1, &histSize, &histRange, uniform, accumulate );
histogram.push_back(singleChannel);
calcHist( &planes[2], 1, 0, Mat(), singleChannel, 1, &histSize, &histRange, uniform, accumulate );
histogram.push_back(singleChannel);
return histogram;
}
/************************************************
calcHistogram is the same impl for rgb and yuv
************************************************/
Mat blockHistogram(Mat src){
int blockhistSize = SingleBlockBins; /* 8 */
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
Mat singleBlock, allBlocks;
int hDivSize = src.rows/BlocksCount, wDivSize = src.cols/BlocksCount;
int hh = (BlocksCount*hDivSize);
int ww = (BlocksCount*wDivSize);
vector<Mat> planes;
for (int k = 0 ; k < hh ; k+=hDivSize)//k rows
for( int l = 0 ; l < ww ; l+=wDivSize )//l clos
{
Mat roi = src(Rect(l,k,wDivSize,hDivSize));
split( roi, planes );
calcHist( &planes[0], 1, 0, Mat(), singleBlock, 1, &blockhistSize, &histRange, uniform, accumulate );
allBlocks.push_back(singleBlock);
calcHist( &planes[1], 1, 0, Mat(), singleBlock, 1, &blockhistSize, &histRange, uniform, accumulate );
allBlocks.push_back(singleBlock);
calcHist( &planes[2], 1, 0, Mat(), singleBlock, 1, &blockhistSize, &histRange, uniform, accumulate );
allBlocks.push_back(singleBlock);
}
return allBlocks;
}