Commit 8511be7a authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Scalar segmentation is now able to threshold upper and lower thresholds...

[ADD] Scalar segmentation is now able to threshold upper and lower thresholds at the same time and also to binarize or leave values as they are.
parent 3000a29a
......@@ -40,8 +40,7 @@ WMScalarSegmentation::WMScalarSegmentation():
WModule()
{
m_algoIndex = 0;
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoThreshold( WSegmentationAlgoThreshold::LOWER_THRESHOLD ) ) );
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoThreshold( WSegmentationAlgoThreshold::UPPER_THRESHOLD ) ) );
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoThreshold() ) );
#ifdef OW_USE_ITK
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoWatershed() ) );
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoOtsu() ) );
......
......@@ -26,9 +26,8 @@
#include "WSegmentationAlgoThreshold.h"
WSegmentationAlgoThreshold::WSegmentationAlgoThreshold( ThresholdType type )
: WSegmentationAlgo(),
m_type( type )
WSegmentationAlgoThreshold::WSegmentationAlgoThreshold()
: WSegmentationAlgo()
{
}
......@@ -38,46 +37,30 @@ WSegmentationAlgoThreshold::~WSegmentationAlgoThreshold()
void WSegmentationAlgoThreshold::properties()
{
if( m_type == LOWER_THRESHOLD )
{
m_threshold = m_properties->addProperty( "Lower Threshold", "Threshold in %.", 0.0, m_propCondition );
}
else
{
m_threshold = m_properties->addProperty( "Upper Threshold", "Threshold in %.", 0.0, m_propCondition );
}
m_low_threshold = m_properties->addProperty( "Lower Threshold", "Threshold in %.", 0.0, m_propCondition );
m_upp_threshold = m_properties->addProperty( "Upper Threshold", "Threshold in %.", 1.0, m_propCondition );
m_threshold->setMin( 0.0 );
m_threshold->setMax( 1.0 );
m_low_threshold->setMin( 0.0 );
m_low_threshold->setMax( 1.0 );
m_upp_threshold->setMin( 0.0 );
m_upp_threshold->setMax( 1.0 );
m_binarize = m_properties->addProperty( "Binarize", "Replace values with 0 and 1. 0 Means outside, 1 inside.", true, m_propCondition );
}
std::string WSegmentationAlgoThreshold::getName()
{
if( m_type == LOWER_THRESHOLD )
{
return "Lower Threshold segmentation";
}
else
{
return "Upper Threshold segmentation";
}
return "Threshold segmentation";
}
std::string WSegmentationAlgoThreshold::getDescription()
{
if( m_type == LOWER_THRESHOLD )
{
return "Use lower thresholding for segmentation.";
}
else
{
return "Use upper thresholding for segmentation.";
}
return "Use thresholding for segmentation.";
}
bool WSegmentationAlgoThreshold::propChanged()
{
return m_threshold->changed();
return m_low_threshold->changed() || m_upp_threshold->changed() || m_binarize->changed();
}
WSegmentationAlgo::DataSetPtr WSegmentationAlgoThreshold::applyOperation()
......
......@@ -40,21 +40,10 @@
class WSegmentationAlgoThreshold : public WSegmentationAlgo
{
public:
/**
* This flags will select if the threshold should cut lower or upper values to zero.
*/
enum ThresholdType
{
UPPER_THRESHOLD,
LOWER_THRESHOLD
};
/**
* Standard constructor.
*
* \param type Specifies if this instance should act as an Upper or Lower threshold.
*/
explicit WSegmentationAlgoThreshold( ThresholdType type );
WSegmentationAlgoThreshold();
/**
* Destructor.
......@@ -101,13 +90,17 @@ private:
*/
virtual DataSetPtr applyOperation();
//! The threshold in %.
WPropDouble m_threshold;
//! The lower threshold in %.
WPropDouble m_low_threshold;
//! The upper threshold in %.
WPropDouble m_upp_threshold;
/**
* Each instance can select its threshold type which is stored inhere.
* Whether the values inside range of thresholds should be keept, or
* resulting images should contain only 0 or 1 values (binarized).
*/
ThresholdType m_type;
WPropBool m_binarize;
};
template< typename T >
......@@ -115,20 +108,24 @@ WSegmentationAlgo::DataSetPtr WSegmentationAlgoThreshold::operator() ( WValueSet
{
boost::shared_ptr< std::vector< T > > values = boost::shared_ptr< std::vector< T > >( new std::vector< T >( valueset->size() ) );
double threshold = valueset->getMinimumValue() + m_threshold->get( true ) * ( valueset->getMaximumValue() - valueset->getMinimumValue() );
double low_threshold = valueset->getMinimumValue() + m_low_threshold->get( true ) * ( valueset->getMaximumValue() - valueset->getMinimumValue() );
double upp_threshold = valueset->getMinimumValue() + m_upp_threshold->get( true ) * ( valueset->getMaximumValue() - valueset->getMinimumValue() );
if( m_type == LOWER_THRESHOLD )
double val = 0.0;
if( m_binarize->get( true ) )
{
for( std::size_t k = 0; k < valueset->size(); ++k )
{
( *values )[k] = static_cast< T >( static_cast< double >( valueset->getScalar( k ) ) < threshold ? 0 : 1 );
val = static_cast< double >( valueset->getScalar( k ) );
( *values )[k] = static_cast< T >( val < low_threshold || val > upp_threshold ? 0 : 1 );
}
}
else
{
for( std::size_t k = 0; k < valueset->size(); ++k )
{
( *values )[k] = static_cast< T >( static_cast< double >( valueset->getScalar( k ) ) >= threshold ? 0 : 1 );
val = static_cast< double >( valueset->getScalar( k ) );
( *values )[k] = static_cast< T >( val < low_threshold || val > upp_threshold ? 0 : val );
}
}
boost::shared_ptr< WValueSet< T > > vs( new WValueSet< T >( 0, 1, values, DataType< T >::type ) );
......
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