-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbands.pde
98 lines (89 loc) · 2.66 KB
/
bands.pde
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
96
97
98
float getBinValue(Mat _hist, int index){
if(_hist.height()>0){
return (float)_hist.get(index, 0)[0];
}
return 0.0;
}
class ColorBands{
ArrayList<ColorBand> bands;
MyHistogram hist;
//ColorBands(MyHistogram hist_){
// ColorBands(_hist.bins);
//}
ColorBands(MyHistogram hist_){
hist=hist_;
bands=getBands(hist_);
}
//float getValueAt(int index){
// if(index<this.hist.length){
// return (float)this.hist.get(index, 0)[0];
// }
// return 0;
//}
ColorBand getMaxBand(){
ColorBand maxBand = null;
for(int i=0;i<bands.size();i++){
if(maxBand == null || hist.bins[this.bands.get(i).peak] > hist.bins[maxBand.peak]){
maxBand=this.bands.get(i);
}
}
return maxBand;
}
ArrayList<ColorBand> getThreshholdBands(float threshold, float minPeak){
ArrayList<ColorBand> threshholdBands = new ArrayList<ColorBand>();
for(int i=0;i<bands.size();i++){
//if(getValueAt(bands.get(i).peak)*threshold > getValueAt(bands.get(i).left) &&
//getValueAt(bands.get(i).peak)*threshold > getValueAt(bands.get(i).right)){
if(hist.bins[bands.get(i).peak]*threshold > hist.bins[bands.get(i).left] &&
hist.bins[bands.get(i).peak]*threshold > hist.bins[bands.get(i).right] &&
hist.bins[bands.get(i).peak] > minPeak){
threshholdBands.add(bands.get(i));
}
}
return threshholdBands;
}
ArrayList<ColorBand> getBands(MyHistogram hist_){
ArrayList<ColorBand> bands = new ArrayList<ColorBand>();
for(int i=1; i<hist.length-1;i++){
if((float)hist_.bins[i] > (float)hist_.bins[i-1] && (float)hist_.bins[i] > (float)hist_.bins[i+1]){
bands.add(new ColorBand(hist_, i));
}
}
return bands;
}
}
class ColorBand{
int left;
int right;
int peak;
ColorBand(MyHistogram _hist, int _peak){
this.peak=_peak;
this.left=this.getLeft(_hist,_peak);
this.right=this.getRight(_hist,_peak);
}
int getLeft(MyHistogram _hist, int _peak){
for(int i=_peak;i>0;i--){
if((float)_hist.bins[i] < (float)_hist.bins[((i-1)+_hist.length)%_hist.length] && (float)_hist.bins[i] < (float)_hist.bins[(i+1)%_hist.length]){
return i;
}
}
return 1;
}
int getRight(MyHistogram _hist, int _peak){
for(int i=_peak;i<_hist.length;i++){
if((float)_hist.bins[i] < (float)_hist.bins[((i-1)+_hist.length)%_hist.length] && (float)_hist.bins[i] < (float)_hist.bins[(i+1)%_hist.length]){
return i;
}
}
return _hist.length;
}
color getColor(){
color myColor;
pushStyle();
colorMode(HSB);
println("Peak : "+peak);
myColor=color(peak,255,255);
popStyle();
return myColor;
}
}