1 #include <cpPluginsImageFilters/BinaryThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
4 #include <itkBinaryThresholdImageFilter.h>
5 #include <itkBinaryThresholdImageFilter.hxx>
6 #include <itkImageToImageFilter.hxx>
7 #include <itkInPlaceImageFilter.hxx>
8 #include <itkUnaryFunctorImageFilter.hxx>
10 // -------------------------------------------------------------------------
11 cpPluginsImageFilters::BinaryThresholdImageFilter::
12 BinaryThresholdImageFilter( )
15 this->_AddInput( "Input" );
16 this->_AddOutput< cpPlugins::Image >( "Output" );
18 this->m_Parameters.ConfigureAsReal( "LowerThresholdValue" );
19 this->m_Parameters.ConfigureAsReal( "UpperThresholdValue" );
20 this->m_Parameters.ConfigureAsUint( "InsideValue" );
21 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
23 this->m_Parameters.SetReal( "LowerThresholdValue", 0 );
24 this->m_Parameters.SetReal( "UpperThresholdValue", 10000 );
25 this->m_Parameters.SetUint( "InsideValue", 1 );
26 this->m_Parameters.SetUint( "OutsideValue", 0 );
29 // -------------------------------------------------------------------------
30 cpPluginsImageFilters::BinaryThresholdImageFilter::
31 ~BinaryThresholdImageFilter( )
35 // -------------------------------------------------------------------------
36 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
39 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
40 std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
41 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
42 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
43 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
47 // -------------------------------------------------------------------------
49 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
54 this->_GD1< I, itk::Image< unsigned char, I::ImageDimension > >(
60 "ImageFilters::BinaryThresholdImageFilter: No valid input image."
64 // -------------------------------------------------------------------------
65 template< class I, class O >
66 std::string cpPluginsImageFilters::BinaryThresholdImageFilter::
69 typedef itk::BinaryThresholdImageFilter< I, O > _F;
70 typedef typename I::PixelType _IP;
71 typedef typename O::PixelType _OP;
74 _IP lower_val = _IP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
75 _IP upper_val = _IP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
76 _OP in_val = _OP( this->m_Parameters.GetUint( "InsideValue" ) );
77 _OP out_val = _OP( this->m_Parameters.GetUint( "OutsideValue" ) );
80 _F* filter = this->_CreateITK< _F >( );
81 filter->SetInput( image );
82 filter->SetLowerThreshold( lower_val );
83 filter->SetUpperThreshold( upper_val );
84 filter->SetInsideValue( in_val );
85 filter->SetOutsideValue( out_val );
89 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );