1 #include <cpPlugins/Plugins/OtsuThresholdImageFilter.h>
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkOtsuThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::Plugins::OtsuThresholdImageFilter::
8 OtsuThresholdImageFilter( )
11 this->m_ClassName = "cpPlugins::OtsuThresholdImageFilter";
12 this->m_ClassCategory = "ImageToImageFilter";
13 this->SetNumberOfInputs( 1 );
14 this->SetNumberOfOutputs( 1 );
15 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
17 using namespace cpPlugins::Interface;
18 this->m_DefaultParameters.Configure(
19 Parameters::Uint, "NumberOfHistogramBins"
21 this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" );
22 this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" );
23 this->m_DefaultParameters.SetValueAsUint( "NumberOfHistogramBins", 100 );
24 this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 );
25 this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 );
26 this->m_Parameters = this->m_DefaultParameters;
29 // -------------------------------------------------------------------------
30 cpPlugins::Plugins::OtsuThresholdImageFilter::
31 ~OtsuThresholdImageFilter( )
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
39 cpPlugins::Interface::Image* image =
40 this->GetInput< cpPlugins::Interface::Image >( 0 );
42 return( "OtsuThresholdImageFilter: No input image." );
44 itk::DataObject* itk_image = NULL;
46 cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
47 2, image, itk_image, r, _DemangleOutput
49 else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
50 3, image, itk_image, r, _DemangleOutput
52 else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
53 4, image, itk_image, r, _DemangleOutput
55 else r = "OtsuThresholdImageFilter: Input image type not supported.";
59 // -------------------------------------------------------------------------
61 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
62 _DemangleOutput( itk::DataObject* image )
65 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
71 // -------------------------------------------------------------------------
72 template< class I, class O >
73 inline std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
74 _RealGD( itk::DataObject* image )
76 typedef itk::OtsuThresholdImageFilter< I, O > _F;
77 typedef typename O::PixelType _OP;
81 this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
82 _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
83 _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
86 _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
89 this->m_RealProcessObject = _F::New( );
90 filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
93 filter->SetInput( dynamic_cast< I* >( image ) );
94 filter->SetNumberOfHistogramBins( bins );
95 filter->SetInsideValue( in_val );
96 filter->SetOutsideValue( out_val );
100 cpPlugins::Interface::Image* out =
101 this->GetOutput< cpPlugins::Interface::Image >( 0 );
104 out->SetITKImage< O >( filter->GetOutput( ) );
108 return( "OtsuThresholdImageFilter: output not correctly created." );