MCPcopy Create free account
hub / github.com/cpvrlab/ImagePlay / IPLHistogram

Method IPLHistogram

IPL/include/IPLHistogram.h:33–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31{
32public:
33 IPLHistogram(IPLImagePlane* plane, int bins, int range)
34 {
35 _plane = plane;
36 _bins = bins;
37 _range = range;
38
39 _histogram.clear();
40
41 // statistics
42 _minLevel = 255;
43 _maxLevel = 0;
44 _meanLevel = 0;
45 _medianLevel = 0;
46 _modeLevel = 0;
47 _totalValues = 0;
48
49 // normalize to range
50 _maxCount = 0;
51 _maxCountLog = 0;
52
53 long total = 0;
54
55 if(_plane->height()*_plane->width() == 0)
56 return;
57
58 // create bins
59 for(int i=0; i<_bins; i++)
60 {
61 _histogram.push_back(0);
62 }
63
64 // collect data
65 for(int y=0; y<plane->height(); y++)
66 {
67 for(int x=0; x<plane->width(); x++)
68 {
69 unsigned char value = plane->p(x,y) * FACTOR_TO_UCHAR;
70 int i = (value * _bins / 256);
71 if(i<_bins)
72 _histogram[i]++;
73
74 total += value;
75 }
76 }
77
78 // collect statistics
79 _meanLevel = (float) total / (float) (plane->width()*plane->height());
80 for(uint i=0; i < _histogram.size(); i++)
81 {
82 // mode
83 _totalValues += _histogram[i];
84 if(_histogram[i] > _maxCount)
85 {
86 _maxCount = _histogram[i];
87 _modeLevel = i;
88 }
89 _maxCount = std::max(_maxCount, _histogram[i]);
90

Callers

nothing calls this directly

Calls 7

logFunction · 0.85
heightMethod · 0.80
widthMethod · 0.80
maxFunction · 0.70
clearMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected