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 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
35 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
36 std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
37 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
39 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
40 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
45 // -------------------------------------------------------------------------
46 template< class _TImage >
47 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
48 _GD0( _TImage* image )
51 return( this->_GD1< _TImage, unsigned char >( image ) );
54 "ImageFilters::BinaryThresholdImageFilter: No valid input image."
58 // -------------------------------------------------------------------------
59 template< class _TImage, class _TBinaryPixel >
60 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
61 _GD1( _TImage* image )
63 typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
64 typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
65 typedef typename _TImage::PixelType _TP;
68 _TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
69 _TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
70 _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
71 _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
74 _F* filter = this->_CreateITK< _F >( );
75 filter->SetInput( image );
76 filter->SetLowerThreshold( lower_val );
77 filter->SetUpperThreshold( upper_val );
78 filter->SetInsideValue( in_val );
79 filter->SetOutsideValue( out_val );
83 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );