1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/ThresholdFilters.h>
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::BinaryThresholdImageFilter::
7 BinaryThresholdImageFilter( )
10 this->_AddInput( "Input" );
11 this->_AddOutput< cpPlugins::Image >( "Output" );
13 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
14 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
15 this->m_Parameters.ConfigureAsUint( "InsideValue" );
16 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
18 this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
19 this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
20 this->m_Parameters.SetReal( "InsideValue", 1 );
21 this->m_Parameters.SetReal( "OutsideValue", 0 );
22 this->m_Parameters.SetSelectedChoice( "OutputResolution", "unsigned char" );
25 // -------------------------------------------------------------------------
26 cpPluginsImageFilters::BinaryThresholdImageFilter::
27 ~BinaryThresholdImageFilter( )
31 // -------------------------------------------------------------------------
32 void cpPluginsImageFilters::BinaryThresholdImageFilter::
35 auto image = this->GetInputData< itk::DataObject >( "Input" );
36 cpPlugins_Image_Demangle_Pixel_AllScalars ( _GD0, image, 2 );
37 else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
38 else this->_Error( "No valid input image." );
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsImageFilters::BinaryThresholdImageFilter::
44 _GD0( _TImage* image )
47 this->_GD1< _TImage, unsigned char >( image );
49 this->_Error( "No valid input image." );
52 // -------------------------------------------------------------------------
53 template< class _TImage, class _TBinaryPixel >
54 void cpPluginsImageFilters::BinaryThresholdImageFilter::
55 _GD1( _TImage* image )
57 typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
58 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
59 typedef typename _TImage::PixelType _TP;
62 _TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
63 _TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
64 _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
65 _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
68 _F* filter = this->_CreateITK< _F >( );
69 filter->SetInput( image );
70 filter->SetLowerThreshold( lower_val );
71 filter->SetUpperThreshold( upper_val );
72 filter->SetInsideValue( in_val );
73 filter->SetOutsideValue( out_val );
77 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );