1 #include <ImageThresholdFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
11 typedef cpPlugins::DataObjects::Image _TImage;
12 this->_ConfigureInput< _TImage >( "Input", true, false );
13 this->_ConfigureOutput< _TImage >( "Output" );
15 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
16 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
17 this->m_Parameters.ConfigureAsUint( "InsideValue" );
18 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
20 this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
21 this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
22 this->m_Parameters.SetUint( "InsideValue", 1 );
23 this->m_Parameters.SetUint( "OutsideValue", 0 );
26 // -------------------------------------------------------------------------
27 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
28 ~BinaryThresholdImageFilter( )
32 // -------------------------------------------------------------------------
33 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
37 auto o = this->GetInputData( "Input" );
38 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39 else this->_Error( "Invalid input image." );
43 // -------------------------------------------------------------------------
44 template< class _TImage >
45 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
46 _GD0( _TImage* image )
49 typedef unsigned char _TBin;
50 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
51 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
52 typedef typename _TImage::PixelType _TPixel;
55 _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
56 _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
57 _TBin iv = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
58 _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
61 _TFilter* filter = this->_CreateITK< _TFilter >( );
62 filter->SetInput( image );
63 filter->SetLowerThreshold( lt );
64 filter->SetUpperThreshold( ut );
65 filter->SetInsideValue( iv );
66 filter->SetOutsideValue( ov );
70 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );