mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-02 01:30:34 -06:00
Find highest value over multiple bins in histogram
This commit is contained in:
@@ -71,7 +71,7 @@ public:
|
||||
float equalize (float);
|
||||
float entropy();
|
||||
|
||||
float highestBinValue(bool equalized);
|
||||
float highestBinValue(bool equalized, int overBins=0);
|
||||
float binWidth();
|
||||
|
||||
void changeRange(float minValue, float maxValue);
|
||||
|
||||
@@ -307,17 +307,41 @@ void Histogram::print() const {
|
||||
std::cout << std::endl << std::endl << std::endl<< "==============" << std::endl;
|
||||
}
|
||||
|
||||
float Histogram::highestBinValue(bool equalized){
|
||||
float Histogram::highestBinValue(bool equalized, int overBins){
|
||||
int highestBin = 0;
|
||||
float highestValue = 0;
|
||||
|
||||
for(int i=0; i<_numBins; i++){
|
||||
if(_data[i] > _data[highestBin])
|
||||
float value = 0;
|
||||
int num = 0;
|
||||
for(int j=0; j<overBins; j++){
|
||||
if(i-j>0){
|
||||
value += _data[i-j];
|
||||
num++;
|
||||
}
|
||||
if(i+j<_numBins){
|
||||
value += _data[i+j];
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
value += _data[i];
|
||||
value /= (float)++num;
|
||||
|
||||
if(value > highestValue){
|
||||
highestBin = i;
|
||||
highestValue = value;
|
||||
}
|
||||
|
||||
// if(_data[i] > _data[highestBin])
|
||||
// highestBin = i;
|
||||
}
|
||||
|
||||
float low = _minValue + float(highestBin) / _numBins * (_maxValue - _minValue);
|
||||
float high = low + (_maxValue - _minValue) / float(_numBins);
|
||||
|
||||
if(!equalized){
|
||||
std::cout << (high+low)/2.0 << std::endl;
|
||||
return (high+low)/2.0;
|
||||
}else{
|
||||
return equalize((high+low)/2.0);
|
||||
|
||||
Reference in New Issue
Block a user