From a7ecb3b53f6688a84e4e5415486786863f72d672 Mon Sep 17 00:00:00 2001 From: jose guzman Date: Wed, 7 Oct 2015 17:13:03 +0200 Subject: [PATCH] Binary Erode Image Filter Added --- .../BasicFilters/BinaryErodeImageFilter.cxx | 102 ++++++++++++++++++ .../BasicFilters/BinaryErodeImageFilter.h | 56 ++++++++++ 2 files changed, 158 insertions(+) create mode 100644 lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx create mode 100644 lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx new file mode 100644 index 0000000..32c8d05 --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.cxx @@ -0,0 +1,102 @@ +#include "BinaryErodeImageFilter.h" +#include + +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::BinaryErodeImageFilter:: +BinaryErodeImageFilter( ) + : Superclass( ) +{ + this->m_ClassName = "cpPlugins::BasicFilters::BinaryErodeImageFilter"; + 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, "Radius" ); + + this->m_DefaultParameters.SetValueAsUint( "Radius", 2 ); + + this->m_Parameters = this->m_DefaultParameters; +} + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::BinaryErodeImageFilter:: +~BinaryErodeImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::BasicFilters::BinaryErodeImageFilter:: +_GenerateData( ) +{ + cpPlugins::Interface::Image* image = + this->GetInput< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "BinaryErodeImageFilter: No input image." ); + + itk::DataObject* itk_image = NULL; + std::string r = ""; + cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); + else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); + else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 ); + else r = "BinaryErodeImageFilter: Input image type not supported."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::BasicFilters::BinaryErodeImageFilter:: +_GD0( itk::DataObject* image ) +{ + return( + this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( + image + ) + ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +inline std::string cpPlugins::BasicFilters::BinaryErodeImageFilter:: +_RealGD( itk::DataObject* image ) +{ + //typedef itk::Image ImageType; + typedef itk::BinaryBallStructuringElement< I::PixelType, I::ImageDimension> StructuringElementType; + typedef itk::BinaryErodeImageFilter< I, O, StructuringElementType > _F; + typedef typename _F::RadiusType _RT; + + // Get parameters + _RT rad_val; + rad_val.Fill( this->m_Parameters.GetValueAsUint( "Radius" ) ); + + // Configure filter + + StructuringElementType structuringElement; + structuringElement.SetRadius(rad_val); + structuringElement.CreateStructuringElement(); + + + + _F* filter = this->_CreateITK< _F >( ); + filter->SetInput( dynamic_cast< I* >( image ) ); + filter->SetKernel(structuringElement); + filter->Update( ); + + // Connect output + cpPlugins::Interface::Image* out = + this->GetOutput< cpPlugins::Interface::Image >( 0 ); + if( out != NULL ) + { + out->SetITK< O >( filter->GetOutput( ) ); + return( "" ); + } + else + return( "BinaryErodeImageFilter: output not correctly created." ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h new file mode 100644 index 0000000..5272451 --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h @@ -0,0 +1,56 @@ +#ifndef __CPPLUGINS__PLUGINS__BinaryErodeImageFilter__H__ +#define __CPPLUGINS__PLUGINS__BinaryErodeImageFilter__H__ + +#include +#include + +namespace cpPlugins +{ + namespace BasicFilters + { + /** + */ + class cpPluginsBasicFilters_EXPORT BinaryErodeImageFilter + : public cpPlugins::Interface::ImageToImageFilter + { + public: + typedef BinaryErodeImageFilter Self; + typedef cpPlugins::Interface::ImageToImageFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( + BinaryErodeImageFilter, + cpPluginsInterfaceImageToImageFilter + ); + + protected: + BinaryErodeImageFilter( ); + virtual ~BinaryErodeImageFilter( ); + + virtual std::string _GenerateData( ); + + template< class I > + inline std::string _GD0( itk::DataObject* image ); + + template< class I, class O > + inline std::string _RealGD( itk::DataObject* image ); + + private: + // Purposely not implemented + BinaryErodeImageFilter( const Self& ); + Self& operator=( const Self& ); + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( BinaryErodeImageFilter ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__BinaryErodeImageFilter__H__ + +// eof - $RCSfile$ -- 2.45.2