1 #include <ImageThresholdFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
5 #include <itkBinaryThresholdImageFilter.h>
7 // -------------------------------------------------------------------------
8 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
9 BinaryThresholdImageFilter( )
12 typedef cpPlugins::DataObjects::Image _TImage;
13 this->_ConfigureInput< _TImage >( "Input", true, false );
14 this->_ConfigureOutput< _TImage >( "Output" );
16 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue", 0 );
17 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue", 10000 );
18 this->m_Parameters.ConfigureAsUint( "InsideValue", 1 );
19 this->m_Parameters.ConfigureAsUint( "OutsideValue", 0 );
22 // -------------------------------------------------------------------------
23 cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
24 ~BinaryThresholdImageFilter( )
28 // -------------------------------------------------------------------------
29 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
32 auto o = this->GetInputData( "Input" );
33 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
34 this->_Error( "Invalid input image." );
37 // -------------------------------------------------------------------------
38 template< class _TImage >
39 void cpPluginsImageThresholdFilters::BinaryThresholdImageFilter::
40 _GD0( _TImage* image )
42 typedef unsigned char _TBin;
43 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
44 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
45 typedef typename _TImage::PixelType _TPixel;
48 _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
49 _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
50 _TBin iv = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
51 _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
54 _TFilter* filter = this->_CreateITK< _TFilter >( );
55 filter->SetInput( image );
56 filter->SetLowerThreshold( lt );
57 filter->SetUpperThreshold( ut );
58 filter->SetInsideValue( iv );
59 filter->SetOutsideValue( ov );
63 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );