From a3f2018cdd92e865082fed86673f10207c21ec51 Mon Sep 17 00:00:00 2001 From: jose guzman Date: Fri, 25 Sep 2015 11:29:42 +0200 Subject: [PATCH] median filter added --- lib/cpPlugins/Plugins/Host.cxx | 3 + lib/cpPlugins/Plugins/MedianImageFilter.cxx | 106 ++++++++++++++++++++ lib/cpPlugins/Plugins/MedianImageFilter.h | 53 ++++++++++ 3 files changed, 162 insertions(+) create mode 100644 lib/cpPlugins/Plugins/MedianImageFilter.cxx create mode 100644 lib/cpPlugins/Plugins/MedianImageFilter.h diff --git a/lib/cpPlugins/Plugins/Host.cxx b/lib/cpPlugins/Plugins/Host.cxx index beecbfb..e16e01e 100644 --- a/lib/cpPlugins/Plugins/Host.cxx +++ b/lib/cpPlugins/Plugins/Host.cxx @@ -8,6 +8,7 @@ #include #include #include +#include /// TODO: doc PLUMA_CONNECTOR @@ -24,6 +25,8 @@ bool connect( pluma::Host& host ) host.add( new RGBImageToOtherChannelsFilterProvider( ) ); host.add( new SecondRankDiffusionTensorToPolyDataProvider( ) ); host.add( new BinaryThresholdImageFilterProvider( ) ); + host.add( new MedianImageFilterProvider( ) ); + return( true ); } diff --git a/lib/cpPlugins/Plugins/MedianImageFilter.cxx b/lib/cpPlugins/Plugins/MedianImageFilter.cxx new file mode 100644 index 0000000..e207967 --- /dev/null +++ b/lib/cpPlugins/Plugins/MedianImageFilter.cxx @@ -0,0 +1,106 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::MedianImageFilter:: +MedianImageFilter( ) + : Superclass( ) +{ + this->m_ClassName = "cpPlugins::MedianImageFilter"; + 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, "Radius"); + + this->m_DefaultParameters.SetValueAsReal("Radius", 3); + + this->m_Parameters = this->m_DefaultParameters; +} + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::MedianImageFilter:: +~MedianImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::MedianImageFilter:: +_GenerateData( ) +{ + cpPlugins::Interface::Image* image = + this->GetInput< cpPlugins::Interface::Image >( 0 ); + if( image == NULL ) + return( "MedianImageFilter: 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 = "MedianImageFilter: Input image type not supported."; + return( r ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::string cpPlugins::Plugins::MedianImageFilter:: +_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::MedianImageFilter:: +_RealGD( itk::DataObject* image ) +{ + typedef itk::MedianImageFilter< I, O > _F; + typedef typename O::PixelType _OP; + + // Get parameters + + _OP rad_val = _OP(this->m_Parameters.GetValueAsReal("Radius")); + + + // 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->SetRadius(rad_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( "MedianImageFilter: output not correctly created." ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/MedianImageFilter.h b/lib/cpPlugins/Plugins/MedianImageFilter.h new file mode 100644 index 0000000..3ee8db4 --- /dev/null +++ b/lib/cpPlugins/Plugins/MedianImageFilter.h @@ -0,0 +1,53 @@ +#ifndef __CPPLUGINS__PLUGINS__MEDIANIMAGEFILTER__H__ +#define __CPPLUGINS__PLUGINS__MEDIANIMAGEFILTER__H__ + +#include +#include + +namespace cpPlugins +{ + namespace Plugins + { + /** + */ + class cpPlugins_EXPORT MedianImageFilter + : public cpPlugins::Interface::ImageToImageFilter + { + public: + typedef MedianImageFilter Self; + typedef cpPlugins::Interface::ImageToImageFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( MedianImageFilter, cpPluginsInterfaceImageToImageFilter ); + + protected: + MedianImageFilter( ); + virtual ~MedianImageFilter( ); + + 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 + MedianImageFilter( const Self& ); + Self& operator=( const Self& ); + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( MedianImageFilter ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__MEDIANIMAGEFILTER__H__ + +// eof - $RCSfile$ -- 2.49.0