1 #include <cpPluginsImageFilters/OtsuThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
4 #include <itkOtsuThresholdImageFilter.h>
5 #include <itkBinaryFunctorImageFilter.hxx>
6 #include <itkHistogram.hxx>
7 #include <itkHistogramAlgorithmBase.hxx>
8 #include <itkHistogramThresholdImageFilter.hxx>
9 #include <itkImageToHistogramFilter.hxx>
10 #include <itkMaskedImageToHistogramFilter.hxx>
11 #include <itkOtsuMultipleThresholdsCalculator.hxx>
12 #include <itkOtsuThresholdCalculator.hxx>
14 // -------------------------------------------------------------------------
15 cpPluginsImageFilters::OtsuThresholdImageFilter::
16 OtsuThresholdImageFilter( )
19 this->_AddInput( "Input" );
20 this->_AddOutput< cpPlugins::Image >( "Output" );
22 this->m_Parameters.ConfigureAsUint( "NumberOfHistogramBins" );
23 this->m_Parameters.ConfigureAsUint( "InsideValue" );
24 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
26 this->m_Parameters.SetUint( "NumberOfHistogramBins", 100 );
27 this->m_Parameters.SetUint( "InsideValue", 255 );
28 this->m_Parameters.SetUint( "OutsideValue", 0 );
31 // -------------------------------------------------------------------------
32 cpPluginsImageFilters::OtsuThresholdImageFilter::
33 ~OtsuThresholdImageFilter( )
37 // -------------------------------------------------------------------------
38 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
41 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
42 std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
43 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
44 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
45 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
49 // -------------------------------------------------------------------------
51 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
56 this->_GD1< I, itk::Image< unsigned char, I::ImageDimension > >( image )
59 return( "ImageFilters::OtsuThresholdImageFilter: No valid input image." );
62 // -------------------------------------------------------------------------
63 template< class I, class O >
64 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
67 typedef itk::OtsuThresholdImageFilter< I, O > _F;
68 typedef typename O::PixelType _OP;
71 unsigned int bins = this->m_Parameters.GetUint( "NumberOfHistogramBins" );
72 _OP in_val = _OP( this->m_Parameters.GetUint( "InsideValue" ) );
73 _OP out_val = _OP( this->m_Parameters.GetUint( "OutsideValue" ) );
76 _F* filter = this->_CreateITK< _F >( );
77 filter->SetInput( dynamic_cast< I* >( image ) );
78 filter->SetNumberOfHistogramBins( bins );
79 filter->SetInsideValue( out_val ); // WARNING: these are inverted
80 filter->SetOutsideValue( in_val );
84 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );