-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolordist.cpp
More file actions
69 lines (55 loc) · 1.21 KB
/
Copy pathcolordist.cpp
File metadata and controls
69 lines (55 loc) · 1.21 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <stdio.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
int main(){
Mat src=imread("blue.jpg",1);
int rmax,gmax,bmax,max,scale;
int G[256],R[256],B[256];
for(int i=0;i<256;i++){
G[i]=R[i]=B[i]=0;
}
for(int i=0;i<src.rows;i++){
for(int j=0;j<src.cols;j++){
B[src.at<Vec3b>(i,j)[0]]++;
G[src.at<Vec3b>(i,j)[1]]++;
R[src.at<Vec3b>(i,j)[2]]++;
}
}
rmax=bmax=gmax=0;
for(int i=0;i<256;i++){
if(R[i]>rmax)
rmax=R[i];
if(B[i]>bmax)
bmax=B[i];
if(G[i]>gmax)
gmax=G[i];
}
if(rmax>bmax){
if(rmax>gmax)
max=rmax;
else
max=gmax;
}
else if(bmax>rmax){
if(bmax>gmax)
max=bmax;
else
max=gmax;
}
scale=max/300; //dividing by this scale
cout<<"DONE="<<endl;
int rowmax=(max)/scale+20;
Mat op(rowmax,300,CV_8UC3,Scalar(0,0,0));
for(int i=0;i<256;i++){
op.at<Vec3b>(rowmax-B[i]/scale-5,i)[0]=255;//BLUE
op.at<Vec3b>(rowmax-G[i]/scale-5,i)[1]=255;//GREEN
op.at<Vec3b>(rowmax-R[i]/scale-5,i)[2]=255;//RED
}
namedWindow( "OP", WINDOW_NORMAL );
imshow( "OP",op );
waitKey(0);
}