1 #include "BinaryThresholdImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
11 this->SetNumberOfInputs( 1 );
12 this->SetNumberOfOutputs( 1 );
13 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
15 this->m_Parameters->ConfigureAsReal( "LowerThresholdValue", 0 );
16 this->m_Parameters->ConfigureAsReal( "UpperThresholdValue", 0 );
17 this->m_Parameters->ConfigureAsUint( "InsideValue", 255 );
18 this->m_Parameters->ConfigureAsUint( "OutsideValue", 1 );
21 // -------------------------------------------------------------------------
22 cpPlugins::BasicFilters::BinaryThresholdImageFilter::
23 ~BinaryThresholdImageFilter( )
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
31 cpPlugins::Interface::Image* image =
32 this->GetInput< cpPlugins::Interface::Image >( 0 );
34 return( "BinaryThresholdImageFilter: No input image." );
36 itk::DataObject* itk_image = NULL;
38 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
39 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
40 else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
41 else r = "BinaryThresholdImageFilter: Input image type not supported.";
45 // -------------------------------------------------------------------------
47 std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
48 _GD0( itk::DataObject* image )
51 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
57 // -------------------------------------------------------------------------
58 template< class I, class O >
59 inline std::string cpPlugins::BasicFilters::BinaryThresholdImageFilter::
60 _RealGD( itk::DataObject* image )
62 typedef itk::BinaryThresholdImageFilter< I, O > _F;
63 typedef typename I::PixelType _IP;
64 typedef typename O::PixelType _OP;
68 // this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
69 _IP lower_val = _IP( this->m_Parameters->GetReal( "LowerValue" ) );
70 _IP upper_val = _IP( this->m_Parameters->GetReal( "UpperValue" ) );
71 _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
72 _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
75 _F* filter = this->_CreateITK< _F >( );
76 filter->SetInput( dynamic_cast< I* >( image ) );
77 filter->SetLowerThreshold( lower_val );
78 filter->SetUpperThreshold( upper_val );
79 filter->SetInsideValue( in_val );
80 filter->SetOutsideValue( out_val );
84 cpPlugins::Interface::Image* out =
85 this->GetOutput< cpPlugins::Interface::Image >( 0 );
88 out->SetITK< O >( filter->GetOutput( ) );
92 return( "BinaryThresholdImageFilter: output not correctly created." );