]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/OtsuThresholdImageFilter.cxx
7988bca7bc67700168ec06765874f5ff72568153
[cpPlugins.git] / lib / cpPlugins / Plugins / OtsuThresholdImageFilter.cxx
1 #include <cpPlugins/Plugins/OtsuThresholdImageFilter.h>
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <complex>
5
6 #define ITK_MANUAL_INSTANTIATION
7 #include <itkImage.h>
8
9 #include <itkCovariantVector.h>
10 #include <itkDiffusionTensor3D.h>
11 #include <itkPoint.h>
12 #include <itkRGBPixel.h>
13 #include <itkRGBAPixel.h>
14 #include <itkSymmetricSecondRankTensor.h>
15 #include <itkVector.h>
16
17 #undef ITK_MANUAL_INSTANTIATION
18 #include <itkOtsuThresholdImageFilter.h>
19
20 // -------------------------------------------------------------------------
21 cpPlugins::Plugins::OtsuThresholdImageFilter::
22 OtsuThresholdImageFilter( )
23   : Superclass( )
24 {
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 );
30
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;
39 }
40
41 // -------------------------------------------------------------------------
42 cpPlugins::Plugins::OtsuThresholdImageFilter::
43 ~OtsuThresholdImageFilter( )
44 {
45 }
46
47 // -------------------------------------------------------------------------
48 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
49 _GenerateData( )
50 {
51   itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( );
52   return( this->_DemangleImageDimension( i ) );
53 }
54
55 // -------------------------------------------------------------------------
56 namespace cpPlugins
57 {
58   namespace Plugins
59   {
60     cpPlugins_Image_Demangle_Methods_Code_Only_Scalars(
61       OtsuThresholdImageFilter, _DemangleInput
62       );
63   }
64 }
65
66 // -------------------------------------------------------------------------
67 template< class I >
68 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
69 _DemangleInput( itk::DataObject* image )
70 {
71   return(
72     this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
73       image
74       )
75     );
76 }
77
78 // -------------------------------------------------------------------------
79 template< class I, class O >
80 std::string cpPlugins::Plugins::OtsuThresholdImageFilter::
81 _RealGD( itk::DataObject* image )
82 {
83   typedef itk::OtsuThresholdImageFilter< I, O > _F;
84   typedef typename O::PixelType _OP;
85
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" ) );
89
90   _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
91   if( filter == NULL )
92   {
93     this->m_RealProcessObject = _F::New( );
94     filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) );
95
96   } // fi
97   filter->SetInput( dynamic_cast< I* >( image ) );
98   filter->SetNumberOfHistogramBins( bins );
99   filter->SetInsideValue( in );
100   filter->SetOutsideValue( out );
101   filter->Update( );
102   this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) );
103   
104   return( "" );
105 }
106
107 // eof - $RCSfile$