1 #include "OtsuThresholdImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkOtsuThresholdImageFilter.h>
6 // -------------------------------------------------------------------------
7 cpPlugins::BasicFilters::OtsuThresholdImageFilter::
8 OtsuThresholdImageFilter( )
11 this->_AddInput( "Input" );
12 this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
14 this->m_Parameters->ConfigureAsUint( "NumberOfHistogramBins", 100 );
15 this->m_Parameters->ConfigureAsUint( "InsideValue", 255 );
16 this->m_Parameters->ConfigureAsUint( "OutsideValue", 0 );
19 // -------------------------------------------------------------------------
20 cpPlugins::BasicFilters::OtsuThresholdImageFilter::
21 ~OtsuThresholdImageFilter( )
25 // -------------------------------------------------------------------------
26 std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
29 cpPlugins::Interface::Image* image =
30 this->GetInput< cpPlugins::Interface::Image >( 0 );
32 return( "OtsuThresholdImageFilter: No input image." );
34 itk::DataObject* itk_image = NULL;
36 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
37 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
38 else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
39 else r = "OtsuThresholdImageFilter: Input image type not supported.";
43 // -------------------------------------------------------------------------
45 std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
46 _GD0( itk::DataObject* image )
49 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
55 // -------------------------------------------------------------------------
56 template< class I, class O >
57 inline std::string cpPlugins::BasicFilters::OtsuThresholdImageFilter::
58 _RealGD( itk::DataObject* image )
60 typedef itk::OtsuThresholdImageFilter< I, O > _F;
61 typedef typename O::PixelType _OP;
64 unsigned int bins = this->m_Parameters->GetUint( "NumberOfHistogramBins" );
65 _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
66 _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
69 _F* filter = this->_CreateITK< _F >( );
70 filter->SetInput( dynamic_cast< I* >( image ) );
71 filter->SetNumberOfHistogramBins( bins );
72 filter->SetInsideValue( in_val );
73 filter->SetOutsideValue( out_val );
77 cpPlugins::Interface::Image* out =
78 this->GetOutput< cpPlugins::Interface::Image >( "Output" );
81 out->SetITK< O >( filter->GetOutput( ) );
85 return( "OtsuThresholdImageFilter: output not correctly created." );