#include #include #include #define ITK_MANUAL_INSTANTIATION #include #include #include #include #include #include #include #include #undef ITK_MANUAL_INSTANTIATION #include // ------------------------------------------------------------------------- cpPlugins::Plugins::OtsuThresholdImageFilter:: OtsuThresholdImageFilter( ) : Superclass( ) { this->m_ClassName = "cpPlugins::OtsuThresholdImageFilter"; this->m_ClassCategory = "ImageToImageFilter"; this->SetNumberOfInputs( 1 ); this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); using namespace cpPlugins::Interface; this->m_DefaultParameters.Configure( Parameters::Uint, "NumberOfHistogramBins" ); this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" ); this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" ); this->m_DefaultParameters.SetValueAsUint( "NumberOfHistogramBins", 100 ); this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 ); this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 ); this->m_Parameters = this->m_DefaultParameters; } // ------------------------------------------------------------------------- cpPlugins::Plugins::OtsuThresholdImageFilter:: ~OtsuThresholdImageFilter( ) { } // ------------------------------------------------------------------------- std::string cpPlugins::Plugins::OtsuThresholdImageFilter:: _GenerateData( ) { itk::DataObject* i = this->m_Inputs[ 0 ]->GetITKDataObject( ); return( this->_DemangleImageDimension( i ) ); } // ------------------------------------------------------------------------- namespace cpPlugins { namespace Plugins { cpPlugins_Image_Demangle_Methods_Code_Only_Scalars( OtsuThresholdImageFilter, _DemangleInput ); } } // ------------------------------------------------------------------------- template< class I > std::string cpPlugins::Plugins::OtsuThresholdImageFilter:: _DemangleInput( itk::DataObject* image ) { return( this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( image ) ); } // ------------------------------------------------------------------------- template< class I, class O > std::string cpPlugins::Plugins::OtsuThresholdImageFilter:: _RealGD( itk::DataObject* image ) { typedef itk::OtsuThresholdImageFilter< I, O > _F; typedef typename O::PixelType _OP; unsigned int bins = this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" ); _OP in = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); _OP out = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); _F* filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) ); if( filter == NULL ) { this->m_RealProcessObject = _F::New( ); filter = dynamic_cast< _F* >( this->m_RealProcessObject.GetPointer( ) ); } // fi filter->SetInput( dynamic_cast< I* >( image ) ); filter->SetNumberOfHistogramBins( bins ); filter->SetInsideValue( in ); filter->SetOutsideValue( out ); filter->Update( ); this->m_Outputs[ 0 ]->SetITKDataObject( filter->GetOutput( ) ); return( "" ); } // eof - $RCSfile$