1 #include "BinaryThresholdImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
11 this->_AddInput( "Input" );
12 this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
14 this->m_Parameters->ConfigureAsReal( "LowerThresholdValue" );
15 this->m_Parameters->ConfigureAsReal( "UpperThresholdValue" );
16 this->m_Parameters->ConfigureAsUint( "InsideValue" );
17 this->m_Parameters->ConfigureAsUint( "OutsideValue" );
19 this->m_Parameters->SetReal( "LowerThresholdValue", 0 );
20 this->m_Parameters->SetReal( "UpperThresholdValue", 10000 );
21 this->m_Parameters->SetUint( "InsideValue", 1 );
22 this->m_Parameters->SetUint( "OutsideValue", 0 );
25 // -------------------------------------------------------------------------
26 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
27 ~BinaryThresholdImageFilter( )
31 // -------------------------------------------------------------------------
32 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
35 auto image = this->GetInputData< cpPlugins::Interface::Image >( "Input" );
37 return( "BinaryThresholdImageFilter: No input image." );
39 itk::DataObject* itk_image = NULL;
41 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
42 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
43 else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
44 else r = "BinaryThresholdImageFilter: Input image type not supported.";
48 // -------------------------------------------------------------------------
50 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
51 _GD0( itk::DataObject* image )
54 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
60 // -------------------------------------------------------------------------
61 template< class I, class O >
62 inline std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
63 _RealGD( itk::DataObject* image )
65 typedef itk::BinaryThresholdImageFilter< I, O > _F;
66 typedef typename I::PixelType _IP;
67 typedef typename O::PixelType _OP;
71 // this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
72 _IP lower_val = _IP( this->m_Parameters->GetReal( "LowerThresholdValue" ) );
73 _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperThresholdValue" ) );
74 _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
75 _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
78 _F* filter = this->_CreateITK< _F >( );
79 filter->SetInput( dynamic_cast< I* >( image ) );
80 filter->SetLowerThreshold( lower_val );
81 filter->SetUpperThreshold( upper_val );
82 filter->SetInsideValue( in_val );
83 filter->SetOutsideValue( out_val );
87 auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
90 out->SetITK< O >( filter->GetOutput( ) );
94 return( "BinaryThresholdImageFilter: output not correctly created." );