1 #include <cpPlugins/Plugins/OtsuThresholdImageFilter.h>
2 #include <cpPlugins/Interface/Image.h>
6 #define ITK_MANUAL_INSTANTIATION
9 #include <itkCovariantVector.h>
10 #include <itkDiffusionTensor3D.h>
12 #include <itkRGBPixel.h>
13 #include <itkRGBAPixel.h>
14 #include <itkSymmetricSecondRankTensor.h>
15 #include <itkVector.h>
17 #undef ITK_MANUAL_INSTANTIATION
18 #include <itkOtsuThresholdImageFilter.h>
20 // -------------------------------------------------------------------------
21 cpPlugins::Plugins::OtsuThresholdImageFilter::
22 OtsuThresholdImageFilter( )
25 this->m_ClassName = "cpPlugins::OtsuThresholdImageFilter";
26 this->m_ClassCategory = "ImageToImageFilter";
27 this->SetNumberOfInputs( 1 );
28 this->SetNumberOfOutputs( 1 );
29 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
31 using namespace cpPlugins::Interface;
32 this->m_DefaultParameters.Configure( Parameters::Uint, "NumberOfHistogramBins" );
33 this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" );
34 this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" );
35 this->m_DefaultParameters.SetValueAsUint( "NumberOfHistogramBins", 100 );
36 this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 );
37 this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 );
38 this->m_Parameters = this->m_DefaultParameters;
41 // -------------------------------------------------------------------------
42 cpPlugins::Plugins::OtsuThresholdImageFilter::
43 ~OtsuThresholdImageFilter( )
47 // -------------------------------------------------------------------------
48 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
51 itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( );
52 return( this->_DemangleImageDimension( i ) );
55 // -------------------------------------------------------------------------
60 cpPlugins_Image_Demangle_Methods_Code_Only_Scalars(
61 OtsuThresholdImageFilter, _DemangleInput
66 // -------------------------------------------------------------------------
68 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
69 _DemangleInput( itk::DataObject* image )
72 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
78 // -------------------------------------------------------------------------
79 template< class I, class O >
80 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
81 _RealGD( itk::DataObject* image )
83 typedef itk::OtsuThresholdImageFilter< I, O > _F;
84 typedef typename O::PixelType _OP;
86 unsigned int bins = this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
87 _OP in = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
88 _OP out = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
90 _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
93 this->m_RealProcessObject = _F::New( );
94 filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
97 filter->SetInput( dynamic_cast< I* >( image ) );
98 filter->SetNumberOfHistogramBins( bins );
99 filter->SetInsideValue( in );
100 filter->SetOutsideValue( out );
102 this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) );