#include #include #include #include #include #include // ------------------------------------------------------------------------- cpPluginsImageFilters::OtsuThresholdImageFilter:: OtsuThresholdImageFilter( ) : Superclass( ) { this->_AddInput( "Input" ); this->_AddOutput< cpPlugins::Image >( "Output" ); this->m_Parameters.ConfigureAsUint( "NumberOfHistogramBins" ); this->m_Parameters.ConfigureAsUint( "InsideValue" ); this->m_Parameters.ConfigureAsUint( "OutsideValue" ); this->m_Parameters.SetUint( "NumberOfHistogramBins", 100 ); this->m_Parameters.SetUint( "InsideValue", 255 ); this->m_Parameters.SetUint( "OutsideValue", 0 ); } // ------------------------------------------------------------------------- cpPluginsImageFilters::OtsuThresholdImageFilter:: ~OtsuThresholdImageFilter( ) { } // ------------------------------------------------------------------------- std::string cpPluginsImageFilters::OtsuThresholdImageFilter:: _GenerateData( ) { auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( ); std::string cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 ); if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 ); if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 ); if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 ); return( r ); } // ------------------------------------------------------------------------- template< class _TImage > std::string cpPluginsImageFilters::OtsuThresholdImageFilter:: _GD0( _TImage* image ) { if( image != NULL ) return( this->_GD1< _TImage, unsigned char >( image ) ); else return( "ImageFilters::OtsuThresholdImageFilter: No valid input image." ); } // ------------------------------------------------------------------------- template< class _TImage, class _TBinaryPixel > std::string cpPluginsImageFilters::OtsuThresholdImageFilter:: _GD1( _TImage* image ) { typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage; typedef itk::OtsuThresholdImageFilter< _TImage, _TBinaryImage > _TFilter; // Get parameters unsigned int bins = this->m_Parameters.GetUint( "NumberOfHistogramBins" ); _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetUint( "InsideValue" ) ); _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetUint( "OutsideValue" ) ); // Configure filter _TFilter* filter = this->_CreateITK< _TFilter >( ); filter->SetInput( image ); filter->SetNumberOfHistogramBins( bins ); filter->SetInsideValue( out_val ); // WARNING: these are inverted filter->SetOutsideValue( in_val ); filter->Update( ); // Connect output this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) ); return( "" ); } // eof - $RCSfile$