Commit 7fbe4e0e authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] Improved scalar segmentation to contain an upper and lower threshold.

parent e54a9d6f
......@@ -40,7 +40,8 @@ WMScalarSegmentation::WMScalarSegmentation():
WModule()
{
m_algoIndex = 0;
m_algos.push_back( boost::shared_ptr< WSegmentationAlgo >( new WSegmentationAlgoThreshold() ) );
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 ) ) );
#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,8 +26,9 @@
#include "WSegmentationAlgoThreshold.h"
WSegmentationAlgoThreshold::WSegmentationAlgoThreshold()
: WSegmentationAlgo()
WSegmentationAlgoThreshold::WSegmentationAlgoThreshold( ThresholdType type )
: WSegmentationAlgo(),
m_type( type )
{
}
......@@ -37,19 +38,41 @@ WSegmentationAlgoThreshold::~WSegmentationAlgoThreshold()
void WSegmentationAlgoThreshold::properties()
{
m_threshold = m_properties->addProperty( "Threshold", "Threshold in %.", 0.0, m_propCondition );
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_threshold->setMin( 0.0 );
m_threshold->setMax( 1.0 );
}
std::string WSegmentationAlgoThreshold::getName()
{
return "Threshold segmentation";
if( m_type == LOWER_THRESHOLD )
{
return "Lower Threshold segmentation";
}
else
{
return "Upper Threshold segmentation";
}
}
std::string WSegmentationAlgoThreshold::getDescription()
{
return "Use thresholding for segmentation.";
if( m_type == LOWER_THRESHOLD )
{
return "Use lower thresholding for segmentation.";
}
else
{
return "Use upper thresholding for segmentation.";
}
}
bool WSegmentationAlgoThreshold::propChanged()
......
......@@ -31,18 +31,30 @@
#include "WSegmentationAlgo.h"
/**
* A very simple threshold segmentation. voxel that have a value smaller than
* the threshold are set to 0, while the rest of the voxels are set to 100.
* A very simple threshold segmentation working in two modi: If in LOWER_THRESHOLD mode than voxel
* that have a value smaller than the threshold are set to 0, while the rest of the voxels are set
* to 1 where as in UPPER_THRESHOLD mode the opposite applies.
*
* \class WSegmentationAlgoThreshold
*/
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.
*/
WSegmentationAlgoThreshold();
explicit WSegmentationAlgoThreshold( ThresholdType type );
/**
* Destructor.
......@@ -91,6 +103,11 @@ private:
//! The threshold in %.
WPropDouble m_threshold;
/**
* Each instance can select its threshold type which is stored inhere.
*/
ThresholdType m_type;
};
template< typename T >
......@@ -99,9 +116,20 @@ 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() );
for( std::size_t k = 0; k < valueset->size(); ++k )
if( m_type == LOWER_THRESHOLD )
{
for( std::size_t k = 0; k < valueset->size(); ++k )
{
( *values )[k] = static_cast< T >( static_cast< double >( valueset->getScalar( k ) ) < threshold ? 0 : 1 );
}
}
else
{
( *values )[k] = static_cast< T >( static_cast< double >( valueset->getScalar( k ) ) < threshold ? 0 : 1 );
for( std::size_t k = 0; k < valueset->size(); ++k )
{
( *values )[k] = static_cast< T >( static_cast< double >( valueset->getScalar( k ) ) >= threshold ? 0 : 1 );
}
}
boost::shared_ptr< WValueSet< T > > vs( new WValueSet< T >( 0, 1, values, DataType< T >::type ) );
return DataSetPtr( new WDataSetScalar( vs, m_dataSet->getGrid() ) );
......
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