Commit 2f8b7254 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - improced histogram a little bit as well as histogram euqalizer.

parent e9828d66
......@@ -254,10 +254,12 @@ std::ostream& operator<<( std::ostream& out, const WValueSetHistogram& h )
{
std::pair< double, double > interval = h.getIntervalForIndex( i );
// NOTE: the notation for open intervals is [a,b) or alternatively [a,b[.
out << i << " = [" << interval.first << ", " << interval.second << ") = " << h[ i ] << std::endl;
//out << i << " = [" << interval.first << ", " << interval.second << ") = " << h[ i ] << std::endl;
out << interval.first << " " << interval.second << " " << std::min( h[ i ], size_t( 3000 ) ) << std::endl;
}
// the last interval is handled special
out << h.size() - 1 << " = [" << h.getIntervalForIndex( h.size() - 1 ).first << ", inf) = " << h[ h.size() - 1 ] << std::endl;
//out << h.size() - 1 << " = [" << h.getIntervalForIndex( h.size() - 1 ).first << ", inf) = " << h[ h.size() - 1 ] << std::endl;
out << h.getIntervalForIndex( h.size() - 1 ).first << " inf " << std::min( h[ h.size() - 1 ], size_t( 3000 ) ) << std::endl;
return out;
}
......
......@@ -270,12 +270,12 @@ inline size_t WValueSetHistogram::getIndexForValue( double value ) const
// the position on the scala
double pos = ( value - m_minimum ) / static_cast< double >( m_mappedBucketSize );
// the index is the floor( position )
size_t idx = static_cast< size_t >( pos );
size_t idx = static_cast< size_t >( std::floor( pos ) );
// is the index larger than the size?
bool inU = ( idx < m_nMappedBuckets );
// is the index smaller than the size?
bool inL = ( pos > 0.0 );
bool inL = ( pos >= 0.0 );
// the trick done here is to clamp value into [m_minimum,m_maximum] without using if statements. The C++ Standard says that booleans are
// always 1 if true.
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <vector>
#include <fstream>
#include <string>
#include "../../kernel/WKernel.h"
......@@ -211,16 +212,20 @@ void WMHistogramEqualization::moduleMain()
curI++;
}
debugLog() << "Clamped " << perc << "% resulting in new interval ["<< lower << ", " << upper <<").";
debugLog() << "Clamped " << perc << "% of [" << hist->getMinimum() << ", " << hist->getMaximum() << "]" << " resulting in new interval [" << lower << ", " << upper <<").";
// with this new interval, extract a new histogram and use it for equalization
hist = boost::shared_ptr< const WValueSetHistogram >( new WValueSetHistogram( valueSet, lower, upper, cdfHistRes ) );
}
// the new data
std::vector< unsigned char > newData;
std::vector< double > newData;
newData.resize( hist->getTotalElementCount(), 0 );
// these values are needed to rescale the data to the original interval
double valueMin = hist->getMinimum();
double valueScaler = hist->getMaximum() - valueMin;
// equalize?
++*progress;
if ( m_equalize->get( true ) )
......@@ -232,24 +237,23 @@ void WMHistogramEqualization::moduleMain()
// go through each CDF item and fill it, which is the sum of all previous items in hist
size_t accum = 0;
double cdfMin = ( *hist )[ 0 ];
double cdfScaler = static_cast< double >( valueSet->rawSize() ) - cdfMin;
for( size_t i = 0; i < hist->size(); ++i )
{
// the CDF at i is the summed up histogram from 0 to i
// we additionally require the histogram to be normalized so divide by the total count
accum += ( *hist )[ i ];
cdf[ i ] = accum;
cdf[ i ] = accum - cdfMin;
}
// finally, build the new dataset
debugLog() << "Calculating equalized value-set";
double cdfMin = cdf[ 0 ];
for ( size_t vi = 0; vi < valueSet->rawSize(); ++vi )
{
double cdfVI = cdf[ hist->getIndexForValue( valueSet->getScalarDouble( vi ) ) ];
newData[ vi ] = static_cast< unsigned char >(
255.0 * ( cdfVI - cdfMin ) / ( static_cast< double >( valueSet->rawSize() ) - cdfMin )
);
size_t idx = hist->getIndexForValue( valueSet->getScalarDouble( vi ) );
double cdfVI = cdf[ idx ];
newData[ vi ] = valueMin + ( valueScaler * cdfVI / cdfScaler );
}
}
else
......@@ -260,7 +264,8 @@ void WMHistogramEqualization::moduleMain()
for ( size_t vi = 0; vi < valueSet->rawSize(); ++vi )
{
size_t idx = hist->getIndexForValue( valueSet->getScalarDouble( vi ) );
newData[ vi ] = static_cast< unsigned char >( static_cast< double >( idx )/ static_cast< double >( maxI ) * 255.0 );
double idxScaled = ( static_cast< double >( idx )/ static_cast< double >( maxI ) );
newData[ vi ] = valueMin + ( valueScaler * idxScaled );
}
}
++*progress;
......@@ -269,14 +274,15 @@ void WMHistogramEqualization::moduleMain()
debugLog() << "Updating output";
// construct
m_output->updateData( boost::shared_ptr< WDataSetScalar >(
boost::shared_ptr< WDataSetScalar > d = boost::shared_ptr< WDataSetScalar >(
new WDataSetScalar( boost::shared_ptr< WValueSetBase >(
new WValueSet< unsigned char >( 0,
new WValueSet< double >( 0,
1,
boost::shared_ptr< std::vector< unsigned char > >(
new std::vector< unsigned char >( newData ) ),
W_DT_UNSIGNED_CHAR ) ), dataSet->getGrid() )
) );
boost::shared_ptr< std::vector< double > >(
new std::vector< double >( newData ) ),
W_DT_DOUBLE ) ), dataSet->getGrid() )
) ;
m_output->updateData( d );
debugLog() << "Done";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment