1 #include <ITKUnaryFunctorFilters/BinaryThresholdImageFilter.h>
2 #include <cpInstances/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
11 typedef cpInstances::Image _TImage;
12 this->_ConfigureInput< _TImage >( "Input", true, false );
13 this->_ConfigureOutput< _TImage >( "Output" );
15 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue", 0 );
16 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue", 1 );
17 this->m_Parameters.ConfigureAsUint( "InsideValue", 1 );
18 this->m_Parameters.ConfigureAsUint( "OutsideValue", 0 );
21 // -------------------------------------------------------------------------
22 cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
23 ~BinaryThresholdImageFilter( )
27 // -------------------------------------------------------------------------
28 void cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
31 auto o = this->GetInputData( "Input" );
32 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
33 this->_Error( "Invalid input image." );
36 // -------------------------------------------------------------------------
37 template< class _TImage >
38 void cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
39 _GD0( _TImage* image )
41 typedef unsigned char _TBin;
42 typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
43 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
44 typedef typename _TImage::PixelType _TPixel;
47 _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
48 _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
49 _TBin iv = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
50 _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
53 _TFilter* filter = this->_CreateITK< _TFilter >( );
54 filter->SetInput( image );
55 filter->SetLowerThreshold( lt );
56 filter->SetUpperThreshold( ut );
57 filter->SetInsideValue( iv );
58 filter->SetOutsideValue( ov );
62 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );