]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 10 Nov 2016 03:06:09 +0000 (22:06 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 10 Nov 2016 03:06:09 +0000 (22:06 -0500)
plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.cxx [new file with mode: 0644]
plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.h [new file with mode: 0644]

diff --git a/plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.cxx b/plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.cxx
new file mode 100644 (file)
index 0000000..5dceb2c
--- /dev/null
@@ -0,0 +1,112 @@
+#include <Plugins/RegionGrowBinaryThresholdWithSeeds.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Image_Demanglers.h>
+
+#include <fpa/Image/Functors/RegionGrowBinaryThreshold.h>
+#include <itkConstNeighborhoodIterator.h>
+#include <vtkPolyData.h>
+
+// -------------------------------------------------------------------------
+fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+RegionGrowBinaryThresholdWithSeeds( )
+  : Superclass( )
+{
+  typedef cpPlugins::BaseObjects::DataObject _TData;
+  typedef cpPlugins::DataObjects::Image _TImage;
+
+  this->_ConfigureInput< _TImage >( "Input", true, false );
+  this->_ConfigureInput< _TData >( "Seeds", true, false );
+  this->_ConfigureOutput< _TData >( "Output" );
+
+  this->m_Parameters.ConfigureAsUint( "Radius", 1 );
+}
+
+// -------------------------------------------------------------------------
+fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+~RegionGrowBinaryThresholdWithSeeds( )
+{
+}
+
+// -------------------------------------------------------------------------
+void fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+_GD0( _TImage* image )
+{
+  typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt;
+  typedef
+    fpa::Image::Functors::RegionGrowBinaryThreshold< _TImage >
+    _TFunctor;
+  auto out = this->GetOutput( "Output" );
+  auto f = out->GetITK< _TFunctor >( );
+  if( f == NULL )
+  {
+    typename _TFunctor::Pointer ptr_f = _TFunctor::New( );
+    f = ptr_f.GetPointer( );
+    out->SetITK( f );
+
+  } // fi
+
+  // Compute thresholds from seeds
+  auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
+  std::vector< typename _TImage::IndexType > indices;
+  if( seeds != NULL )
+  {
+    typename _TImage::PointType pnt;
+    typename _TImage::IndexType idx;
+    unsigned int dim =
+      ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
+
+    for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
+    {
+      double buf[ 3 ];
+      seeds->GetPoint( i, buf );
+      pnt.Fill( 0 );
+      for( unsigned int d = 0; d < dim; ++d )
+        pnt[ d ] = buf[ d ];
+      if( image->TransformPhysicalPointToIndex( pnt, idx ) )
+        indices.push_back( idx );
+
+    } // rof
+
+  } // fi
+
+  typename _TImage::SizeType r;
+  r.Fill( this->m_Parameters.GetUint( "Radius" ) );
+  _TInIt iIt( r, image, image->GetRequestedRegion( ) );
+  double v_s1 = double( 0 );
+  double v_s2 = double( 0 );
+  double v_n = double( 0 );
+  double v_min = std::numeric_limits< double >::max( );
+  double v_max = -v_min;
+  for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt )
+  {
+    iIt.SetLocation( *idxIt );
+    for( unsigned int i = 0; i < iIt.Size( ); ++i )
+    {
+      double v = double( iIt.GetPixel( i ) );
+      v_s1 += v;
+      v_s2 += v * v;
+      v_n += double( 1 );
+      v_min = ( v < v_min )? v: v_min;
+      v_max = ( v_max < v )? v: v_max;
+
+    } // rof
+
+  } // rof
+  double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) );
+  s = std::sqrt( s ) / double( 2 );
+
+  f->SetLowerThreshold( v_min );
+  f->SetUpperThreshold( v_max );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.h b/plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.h
new file mode 100644 (file)
index 0000000..cb8ebe9
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __fpa__Plugins__RegionGrowBinaryThresholdWithSeeds__h__
+#define __fpa__Plugins__RegionGrowBinaryThresholdWithSeeds__h__
+
+#include <fpaPlugins_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace fpaPlugins
+{
+  /**
+   */
+  class fpaPlugins_EXPORT RegionGrowBinaryThresholdWithSeeds
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      RegionGrowBinaryThresholdWithSeeds,
+      cpPlugins::BaseObjects::ProcessObject,
+      fpaFunctors
+      );
+
+  protected:
+    template< class _TImage >
+    inline void _GD0( _TImage* image );
+  };
+
+} // ecapseman
+
+#endif // __fpa__Plugins__RegionGrowBinaryThresholdWithSeeds__h__
+
+// eof - $RCSfile$