]> Creatis software - cpPlugins.git/commitdiff
median filter added
authorjose guzman <jose@gmail.com>
Fri, 25 Sep 2015 09:29:42 +0000 (11:29 +0200)
committerjose guzman <jose@gmail.com>
Fri, 25 Sep 2015 09:29:42 +0000 (11:29 +0200)
lib/cpPlugins/Plugins/Host.cxx
lib/cpPlugins/Plugins/MedianImageFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/MedianImageFilter.h [new file with mode: 0644]

index beecbfbed7293bb783776a1b872e85d6b581b90f..e16e01e42d1759d40f7f958c41c4eec969f083c8 100644 (file)
@@ -8,6 +8,7 @@
 #include <cpPlugins/Plugins/RGBImageToOtherChannelsFilter.h>
 #include <cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h>
 #include <cpPlugins/Plugins/BinaryThresholdImageFilter.h>
+#include <cpPlugins/Plugins/MedianImageFilter.h>
 
 /// 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 (file)
index 0000000..e207967
--- /dev/null
@@ -0,0 +1,106 @@
+#include <cpPlugins/Plugins/MedianImageFilter.h>
+#include <cpPlugins/Interface/Image.h>
+
+#include <itkMedianImageFilter.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..3ee8db4
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef __CPPLUGINS__PLUGINS__MEDIANIMAGEFILTER__H__
+#define __CPPLUGINS__PLUGINS__MEDIANIMAGEFILTER__H__
+
+#include <cpPlugins/Plugins/cpPlugins_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+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$