From 75dc4945344b4a5a7be10a3ca33fa2e6fff87df8 Mon Sep 17 00:00:00 2001 From: jose guzman Date: Thu, 24 Sep 2015 17:51:14 +0200 Subject: [PATCH] binary threshold image filter added --- .../Plugins/BinaryThresholdImageFilter.cxx | 126 ++++++++++++++++++ .../Plugins/BinaryThresholdImageFilter.h | 53 ++++++++ lib/cpPlugins/Plugins/Host.cxx | 2 + 3 files changed, 181 insertions(+) create mode 100644 lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx create mode 100644 lib/cpPlugins/Plugins/BinaryThresholdImageFilter.h diff --git a/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx new file mode 100644 index 0000000..65195e2 --- /dev/null +++ b/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx @@ -0,0 +1,126 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::BinaryThresholdImageFilter:: +BinaryThresholdImageFilter( ) + : Superclass( ) +{ + this->m_ClassName = "cpPlugins::BinaryThresholdImageFilter"; + 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::Real, "LowerThresholdValue"); + this->m_DefaultParameters.Configure(Parameters::Real, "UpperThresholdValue"); + this->m_DefaultParameters.Configure(Parameters::Real, "InsideValue"); + this->m_DefaultParameters.Configure(Parameters::Real, "OutsideValue"); + + this->m_DefaultParameters.SetValueAsReal("LowerThresholdValue", 100); + this->m_DefaultParameters.SetValueAsReal("UpperThresholdValue",500); + this->m_DefaultParameters.SetValueAsReal("InsideValue", 255); + this->m_DefaultParameters.SetValueAsReal("OutsideValue", 0); + + //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::BinaryThresholdImageFilter:: +~BinaryThresholdImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::BinaryThresholdImageFilter:: +_GenerateData( ) +{ + cpPlugins::Interface::Image* image = + this->GetInput< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "BinaryThresholdImageFilter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes( + 2, image, itk_image, r, _DemangleOutput + ); + else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes( + 3, image, itk_image, r, _DemangleOutput + ); + else cpPlugins_Image_Input_Demangle_Dimension_AllScalarTypes( + 4, image, itk_image, r, _DemangleOutput + ); + else r = "BinaryThresholdImageFilter: Input image type not supported."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::Plugins::BinaryThresholdImageFilter:: +_DemangleOutput( itk::DataObject* image ) +{ + return( + this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( + image + ) + ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +inline std::string cpPlugins::Plugins::BinaryThresholdImageFilter:: +_RealGD( itk::DataObject* image ) +{ + typedef itk::BinaryThresholdImageFilter< I, O > _F; + typedef typename O::PixelType _OP; + + // Get parameters + //unsigned int bins = + // this->m_Parameters.GetValueAsUint( "NumberOfHistogramBins" ); + _OP lower_val = _OP(this->m_Parameters.GetValueAsReal("LowerValue")); + _OP upper_val = _OP(this->m_Parameters.GetValueAsReal("UpperValue")); + _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) ); + _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) ); + + // Configure filter + _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->SetLowerThreshold(lower_val); + filter->SetUpperThreshold(upper_val); + filter->SetInsideValue( in_val ); + filter->SetOutsideValue( out_val ); + filter->Update( ); + + // Connect output + cpPlugins::Interface::Image* out = + this->GetOutput< cpPlugins::Interface::Image >( 0 ); + if( out != NULL ) + { + out->SetITKImage< O >( filter->GetOutput( ) ); + return( "" ); + } + else + return( "BinaryThresholdImageFilter: output not correctly created." ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.h b/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.h new file mode 100644 index 0000000..d108fb2 --- /dev/null +++ b/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.h @@ -0,0 +1,53 @@ +#ifndef __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__ +#define __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__ + +#include +#include + +namespace cpPlugins +{ + namespace Plugins + { + /** + */ + class cpPlugins_EXPORT BinaryThresholdImageFilter + : public cpPlugins::Interface::ImageToImageFilter + { + public: + typedef BinaryThresholdImageFilter Self; + typedef cpPlugins::Interface::ImageToImageFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( BinaryThresholdImageFilter, cpPluginsInterfaceImageToImageFilter ); + + protected: + BinaryThresholdImageFilter( ); + virtual ~BinaryThresholdImageFilter( ); + + virtual std::string _GenerateData( ); + + template< class I > + inline std::string _DemangleOutput( itk::DataObject* image ); + + template< class I, class O > + inline std::string _RealGD( itk::DataObject* image ); + + private: + // Purposely not implemented + BinaryThresholdImageFilter( const Self& ); + Self& operator=( const Self& ); + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( BinaryThresholdImageFilter ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/Host.cxx b/lib/cpPlugins/Plugins/Host.cxx index e07b5b0..beecbfb 100644 --- a/lib/cpPlugins/Plugins/Host.cxx +++ b/lib/cpPlugins/Plugins/Host.cxx @@ -7,6 +7,7 @@ #include #include #include +#include /// TODO: doc PLUMA_CONNECTOR @@ -22,6 +23,7 @@ bool connect( pluma::Host& host ) host.add( new OtsuThresholdImageFilterProvider( ) ); host.add( new RGBImageToOtherChannelsFilterProvider( ) ); host.add( new SecondRankDiffusionTensorToPolyDataProvider( ) ); + host.add( new BinaryThresholdImageFilterProvider( ) ); return( true ); } -- 2.47.1