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