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 cpPlugins::Interface::Image* image =
52 this->_Input< cpPlugins::Interface::Image >( 0 );
54 return( "OtsuThresholdImageFilter: No input image." );
56 itk::DataObject* itk_image = NULL;
58 cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
59 2, image, itk_image, r, _DemangleOutput
61 else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
62 3, image, itk_image, r, _DemangleOutput
64 else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes(
65 4, image, itk_image, r, _DemangleOutput
67 else r = "OtsuThresholdImageFilter: Input image type not supported.";
71 // -------------------------------------------------------------------------
73 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
74 _DemangleOutput( itk::DataObject* image )
77 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
83 // -------------------------------------------------------------------------
84 template< class I, class O >
85 inline std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
86 _RealGD( itk::DataObject* image )
88 typedef itk::OtsuThresholdImageFilter< I, O > _F;
89 typedef typename O::PixelType _OP;
93 this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
94 _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
95 _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
98 _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
101 this->m_RealProcessObject = _F::New( );
102 filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
105 filter->SetInput( dynamic_cast< I* >( image ) );
106 filter->SetNumberOfHistogramBins( bins );
107 filter->SetInsideValue( in_val );
108 filter->SetOutsideValue( out_val );
112 cpPlugins::Interface::Image* out =
113 this->_Output< cpPlugins::Interface::Image >( 0 );
116 out->SetITKImage< O >( filter->GetOutput( ) );
120 return( "OtsuThresholdImageFilter: output not correctly created." );
123 // -------------------------------------------------------------------------
129 cpPlugins_Image_Demangle_Methods_Code_Only_Scalars(
130 OtsuThresholdImageFilter, _DemangleInput
135 // -------------------------------------------------------------------------
137 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
138 _DemangleInput( itk::DataObject* image )
142 // -------------------------------------------------------------------------
143 template< class I, class O >
144 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
145 _RealGD( itk::DataObject* image )
147 typedef itk::OtsuThresholdImageFilter< I, O > _F;
148 typedef typename O::PixelType _OP;
150 unsigned int bins = this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" );
151 _OP in = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
152 _OP out = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
154 _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
157 this->m_RealProcessObject = _F::New( );
158 filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
161 filter->SetInput( dynamic_cast< I* >( image ) );
162 filter->SetNumberOfHistogramBins( bins );
163 filter->SetInsideValue( in );
164 filter->SetOutsideValue( out );
166 this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) );