1 #include <plugins/ImageThresholdFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
5 #include <itkBinaryThresholdImageFilter.hxx>
6 #include <itkUnaryFunctorImageFilter.hxx>
8 // -------------------------------------------------------------------------
9 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
10 BinaryThresholdImageFilter( )
13 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
14 this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
16 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
17 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
18 this->m_Parameters.ConfigureAsUint( "InsideValue" );
19 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
21 this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
22 this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
23 this->m_Parameters.SetUint( "InsideValue", 1 );
24 this->m_Parameters.SetUint( "OutsideValue", 0 );
27 // -------------------------------------------------------------------------
28 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
29 ~BinaryThresholdImageFilter( )
33 // -------------------------------------------------------------------------
34 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
37 auto o = this->GetInputData( "Input" );
38 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
39 else this->_Error( "Invalid input image." );
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
45 _GD0( _TImage* image )
47 typedef unsigned char _TBin;
48 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
49 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
50 typedef typename _TImage::PixelType _TPixel;
53 _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
54 _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
55 _TBin iv = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
56 _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
59 _TFilter* filter = this->_CreateITK< _TFilter >( );
60 filter->SetInput( image );
61 filter->SetLowerThreshold( lt );
62 filter->SetUpperThreshold( ut );
63 filter->SetInsideValue( iv );
64 filter->SetOutsideValue( ov );
68 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );