1 #include <ImageDistanceMaps/BinaryContourImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
5 #include <itkBinaryContourImageFilter.h>
7 // -------------------------------------------------------------------------
8 cpPluginsImageDistanceMaps::BinaryContourImageFilter::
9 BinaryContourImageFilter( )
12 typedef cpPlugins::DataObjects::Image _TImage;
14 this->_ConfigureInput< _TImage >( "Input", true, false );
15 this->_ConfigureOutput< _TImage >( "Output" );
17 this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
18 this->m_Parameters.ConfigureAsReal( "ForegroundValue" );
19 this->m_Parameters.ConfigureAsBool( "FullyConnected" );
21 this->m_Parameters.SetReal( "BackgroundValue", 0 );
22 this->m_Parameters.SetReal( "ForegroundValue", 1 );
23 this->m_Parameters.SetBool( "FullyConnected", false );
26 // -------------------------------------------------------------------------
27 cpPluginsImageDistanceMaps::BinaryContourImageFilter::
28 ~BinaryContourImageFilter( )
32 // -------------------------------------------------------------------------
33 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
36 auto o = this->GetInputData( "Input" );
37 cpPlugins_Demangle_Image_VisualDims( o, _GD0, )
38 this->_Error( "Invalid input image dimension." );
41 // -------------------------------------------------------------------------
42 template< class _TImage >
43 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
44 _GD0( _TImage* image )
46 cpPlugins_Demangle_Image_ScalarPixels( image, _GD1, _TImage::ImageDimension, )
47 this->_Error( "Invalid input image pixel type." );
50 // -------------------------------------------------------------------------
51 template< class _TImage >
52 void cpPluginsImageDistanceMaps::BinaryContourImageFilter::
53 _GD1( _TImage* image )
56 itk::BinaryContourImageFilter< _TImage, _TImage >
60 double b = this->m_Parameters.GetReal( "BackgroundValue" );
61 double f = this->m_Parameters.GetReal( "ForegroundValue" );
62 double c = this->m_Parameters.GetBool( "FullyConnected" );
65 _TFilter* filter = this->_CreateITK< _TFilter >( );
66 filter->SetInput( image );
67 filter->SetBackgroundValue( ( typename _TImage::PixelType )( b ) );
68 filter->SetForegroundValue( ( typename _TImage::PixelType )( f ) );
69 filter->SetFullyConnected( c );
73 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );