]> Creatis software - cpPlugins.git/commitdiff
binary threshold image filter added
authorjose guzman <jose@gmail.com>
Thu, 24 Sep 2015 15:51:14 +0000 (17:51 +0200)
committerjose guzman <jose@gmail.com>
Thu, 24 Sep 2015 15:51:14 +0000 (17:51 +0200)
lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/BinaryThresholdImageFilter.h [new file with mode: 0644]
lib/cpPlugins/Plugins/Host.cxx

diff --git a/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx b/lib/cpPlugins/Plugins/BinaryThresholdImageFilter.cxx
new file mode 100644 (file)
index 0000000..65195e2
--- /dev/null
@@ -0,0 +1,126 @@
+#include <cpPlugins/Plugins/BinaryThresholdImageFilter.h>
+#include <cpPlugins/Interface/Image.h>
+
+#include <itkBinaryThresholdImageFilter.h>
+
+// -------------------------------------------------------------------------
+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 (file)
index 0000000..d108fb2
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__
+#define __CPPLUGINS__PLUGINS__BINARYTHRESHOLDIMAGEFILTER__H__
+
+#include <cpPlugins/Plugins/cpPlugins_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+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$
index e07b5b0702a2ce5b0a029517830ee098a32a4cf1..beecbfbed7293bb783776a1b872e85d6b581b90f 100644 (file)
@@ -7,6 +7,7 @@
 #include <cpPlugins/Plugins/OtsuThresholdImageFilter.h>
 #include <cpPlugins/Plugins/RGBImageToOtherChannelsFilter.h>
 #include <cpPlugins/Plugins/SecondRankDiffusionTensorToPolyData.h>
+#include <cpPlugins/Plugins/BinaryThresholdImageFilter.h>
 
 /// 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 );
 }