1 #include <cpPluginsImageFilters/OtsuThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_ITKInstances/ImageFilters.h>
5 #include <itkOtsuThresholdImageFilter.h>
6 #include <itkOtsuMultipleThresholdsCalculator.hxx>
7 #include <itkOtsuThresholdCalculator.hxx>
9 // -------------------------------------------------------------------------
10 cpPluginsImageFilters::OtsuThresholdImageFilter::
11 OtsuThresholdImageFilter( )
14 this->_AddInput( "Input" );
15 this->_AddOutput< cpPlugins::Image >( "Output" );
17 this->m_Parameters.ConfigureAsUint( "NumberOfHistogramBins" );
18 this->m_Parameters.ConfigureAsUint( "InsideValue" );
19 this->m_Parameters.ConfigureAsUint( "OutsideValue" );
21 this->m_Parameters.SetUint( "NumberOfHistogramBins", 100 );
22 this->m_Parameters.SetUint( "InsideValue", 255 );
23 this->m_Parameters.SetUint( "OutsideValue", 0 );
26 // -------------------------------------------------------------------------
27 cpPluginsImageFilters::OtsuThresholdImageFilter::
28 ~OtsuThresholdImageFilter( )
32 // -------------------------------------------------------------------------
33 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
36 auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
37 std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
38 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
39 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
40 if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
44 // -------------------------------------------------------------------------
45 template< class _TImage >
46 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
47 _GD0( _TImage* image )
50 return( this->_GD1< _TImage, unsigned char >( image ) );
52 return( "ImageFilters::OtsuThresholdImageFilter: No valid input image." );
55 // -------------------------------------------------------------------------
56 template< class _TImage, class _TBinaryPixel >
57 std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
58 _GD1( _TImage* image )
60 typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
61 typedef itk::OtsuThresholdImageFilter< _TImage, _TBinaryImage > _TFilter;
64 unsigned int bins = this->m_Parameters.GetUint( "NumberOfHistogramBins" );
65 _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetUint( "InsideValue" ) );
66 _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetUint( "OutsideValue" ) );
69 _TFilter* filter = this->_CreateITK< _TFilter >( );
70 filter->SetInput( image );
71 filter->SetNumberOfHistogramBins( bins );
72 filter->SetInsideValue( out_val ); // WARNING: these are inverted
73 filter->SetOutsideValue( in_val );
77 this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );