30 #include "WMHistogramEqualization.h"
31 #include "WMHistogramEqualization.xpm"
32 #include "core/common/WPropertyHelper.h"
33 #include "core/dataHandler/WDataHandler.h"
34 #include "core/kernel/WKernel.h"
56 return WMHistogramEqualization_xpm;
61 return "Histogram Equalization";
66 return "This module takes an arbitrary data set and equalizes its histogram. This increases contrast in several regions of the data.";
72 m_input = std::shared_ptr< WModuleInputData < WDataSetScalar > >(
74 "in",
"The dataset whose histogram gets equalized." )
79 m_output = std::shared_ptr< WModuleOutputData < WDataSetScalar > >(
81 "out",
"The dataset which has a linear cumulative histogram." )
96 m_clamp =
m_clamping->addProperty(
"Clamp values?",
"Values below the specified threshold are clamped to min and max respectively.",
104 m_clampPerc =
m_clamping->addProperty(
"Min-Max clamping in %",
"Percent that are clamped from the beginning and the end of the histogram.",
112 m_equalize =
m_equalizing->addProperty(
"Equalize histogram",
"If true, the dataset's cumulative histogram gets linearized.",
116 "How many buckets should be used for the data histogram used for equalizing?",
148 bool dataUpdated =
m_input->updated();
151 std::shared_ptr< WDataSetScalar > dataSet =
m_input->getData();
158 std::shared_ptr< WValueSetBase > valueSet = dataSet->getValueSet();
159 dataUpdated = dataUpdated && dataSet;
162 std::shared_ptr< WProgress > progress(
new WProgress(
"Processing", 4 ) );
168 debugLog() <<
"Calculating histogram with resolution " << histRes;
171 std::shared_ptr< const WValueSetHistogram > hist = dataSet->getHistogram( histRes );
175 double lower = hist->getMinimum();
176 double upper = hist->getMaximum();
188 size_t accumMax =
static_cast< size_t >(
static_cast< double >( hist->getTotalElementCount() ) * perc / 100.0 );
192 size_t maxI = hist->size() - 1;
195 while( curI <= maxI )
197 accumL += ( *hist )[ curI ];
198 accumU += ( *hist )[ maxI - curI ];
201 if( !foundL && ( accumL >= accumMax ) )
204 lower = hist->getIntervalForIndex( curI ).first;
206 if( !foundU && ( accumU >= accumMax ) )
209 upper = hist->getIntervalForIndex( maxI - curI ).second;
215 debugLog() <<
"Clamped " << perc <<
"% of [" << hist->getMinimum() <<
", " << hist->getMaximum() <<
"]" <<
216 " resulting in new interval [" << lower <<
", " << upper <<
").";
219 hist = std::shared_ptr< const WValueSetHistogram >(
new WValueSetHistogram( valueSet, lower, upper, cdfHistRes ) );
223 std::vector< double > newData;
224 newData.resize( hist->getTotalElementCount(), 0 );
227 double valueMin = hist->getMinimum();
228 double valueScaler = hist->getMaximum() - valueMin;
235 debugLog() <<
"Calculating cumulative distribution function";
236 std::vector< double > cdf;
237 cdf.resize( hist->size() );
241 double cdfMin = ( *hist )[ 0 ];
242 double cdfScaler =
static_cast< double >( valueSet->rawSize() ) - cdfMin;
243 for(
size_t i = 0; i < hist->size(); ++i )
247 accum += ( *hist )[ i ];
248 cdf[ i ] = accum - cdfMin;
252 debugLog() <<
"Calculating equalized value-set";
253 for(
size_t vi = 0; vi < valueSet->rawSize(); ++vi )
255 size_t idx = hist->getIndexForValue( valueSet->getScalarDouble( vi ) );
256 double cdfVI = cdf[ idx ];
257 newData[ vi ] = valueMin + ( valueScaler * cdfVI / cdfScaler );
263 debugLog() <<
"Calculating value-set";
264 size_t maxI = hist->size() - 1;
265 for(
size_t vi = 0; vi < valueSet->rawSize(); ++vi )
267 size_t idx = hist->getIndexForValue( valueSet->getScalarDouble( vi ) );
268 double idxScaled = (
static_cast< double >( idx )/
static_cast< double >( maxI ) );
269 newData[ vi ] = valueMin + ( valueScaler * idxScaled );
278 std::shared_ptr< WDataSetScalar > d = std::shared_ptr< WDataSetScalar >(
282 std::shared_ptr< std::vector< double > >(
283 new std::vector< double >( newData ) ),
284 W_DT_DOUBLE ) ), dataSet->getGrid() )
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
This data set type contains scalars as values.
This modules takes a dataset and equalizes its histogram.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
WMHistogramEqualization()
Default constructor.
virtual void connectors()
Initialize the connectors this module is using.
WPropInt m_histogramResolution
Resolution of the initial histogram.
WPropBool m_equalize
If true, histogram equalization is turned on.
virtual void moduleMain()
Entry point after loading the module.
WPropGroup m_equalizing
Group for keeping all the equalizing-related props.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_input
An input connector used to get datasets from other modules.
virtual const std::string getName() const
Gives back the name of this module.
WPropDouble m_clampPerc
How many percent should be clamped from the histogram.
virtual ~WMHistogramEqualization()
Destructor.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The output connector used to provide the calculated data to other modules.
WPropGroup m_clamping
Group for keeping all the clamping related props.
virtual void properties()
Initialize the properties for this module.
WPropBool m_clamp
True if the values should be clamped before further processing.
WPropInt m_cdfResolution
Resolution with which the CDF gets calculated.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
std::shared_ptr< WProperties > m_properties
The property object for the module.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
virtual void connectors()
Initialize connectors in this function.
Class managing progress inside of modules.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Used to find the occurrence frequencies of values in a value set.
Base Class for all value set types.