]> Creatis software - cpPlugins.git/blob - plugins/ITKUnaryFunctorFilters/BinaryThresholdImageFilter.cxx
4f103f67a2136b421f39427531182009a74fe532
[cpPlugins.git] / plugins / ITKUnaryFunctorFilters / BinaryThresholdImageFilter.cxx
1 #include <ITKUnaryFunctorFilters/BinaryThresholdImageFilter.h>
2 #include <cpInstances/Image.h>
3
4 #include <itkBinaryThresholdImageFilter.h>
5
6 // -------------------------------------------------------------------------
7 cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
8 BinaryThresholdImageFilter( )
9   : Superclass( )
10 {
11   typedef cpInstances::Image _TImage;
12   this->_ConfigureInput< _TImage >( "Input", true, false );
13   this->_ConfigureOutput< _TImage >( "Output" );
14
15   this->m_Parameters.ConfigureAsReal( "LowerThresholdValue", 0 );
16   this->m_Parameters.ConfigureAsReal( "UpperThresholdValue", 1 );
17   this->m_Parameters.ConfigureAsUint( "InsideValue", 1 );
18   this->m_Parameters.ConfigureAsUint( "OutsideValue", 0 );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
23 ~BinaryThresholdImageFilter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 void cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
29 _GenerateData( )
30 {
31   auto o = this->GetInputData( "Input" );
32   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
33     this->_Error( "Invalid input image." );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class _TImage >
38 void cpPluginsITKUnaryFunctorFilters::BinaryThresholdImageFilter::
39 _GD0( _TImage* image )
40 {
41   typedef unsigned char _TBin;
42   typedef itk::Image< unsigned char, _TImage::ImageDimension > _TBinImage;
43   typedef itk::BinaryThresholdImageFilter< _TImage, _TBinImage > _TFilter;
44   typedef typename _TImage::PixelType _TPixel;
45
46   // Get parameters
47   _TPixel lt = _TPixel( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
48   _TPixel ut = _TPixel( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
49   _TBin iv  = _TBin( this->m_Parameters.GetUint( "InsideValue" ) );
50   _TBin ov = _TBin( this->m_Parameters.GetUint( "OutsideValue" ) );
51
52   // Configure filter
53   _TFilter* filter = this->_CreateITK< _TFilter >( );
54   filter->SetInput( image );
55   filter->SetLowerThreshold( lt );
56   filter->SetUpperThreshold( ut );
57   filter->SetInsideValue( iv );
58   filter->SetOutsideValue( ov );
59   filter->Update( );
60
61   // Connect output
62   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
63 }
64
65 // eof - $RCSfile$