]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx
... and on linux again
[cpPlugins.git] / plugins / cpPluginsImageFilters / HistogramThresholdImageFilter.cxx
1 #include <cpPluginsImageFilters/HistogramThresholdImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_ITKInstances/ImageFilters.h>
4
5 #include <itkHistogramThresholdImageFilter.h>
6 #include <itkHistogramThresholdImageFilter.hxx>
7 #include <itkBinaryFunctorImageFilter.hxx>
8
9 // -------------------------------------------------------------------------
10 cpPluginsImageFilters::HistogramThresholdImageFilter::
11 HistogramThresholdImageFilter( )
12   : Superclass( )
13 {
14   this->_AddInput( "Input" );
15   this->_AddInput( "Calculator" );
16   this->_AddInput( "Mask", false );
17   this->_AddOutput< cpPlugins::Image >( "Output" );
18
19   this->m_Parameters.ConfigureAsUint( "NumberOfHistogramBins" );
20   this->m_Parameters.ConfigureAsBool( "AutoMinimumMaximum" );
21   this->m_Parameters.ConfigureAsBool( "MaskOutput" );
22   this->m_Parameters.ConfigureAsReal( "MaskValue" );
23   this->m_Parameters.ConfigureAsReal( "Threshold" );
24
25   this->m_Parameters.SetUint( "NumberOfHistogramBins", 256 );
26   this->m_Parameters.SetBool( "AutoMinimumMaximum", true );
27   this->m_Parameters.SetBool( "MaskOutput", false );
28   this->m_Parameters.SetReal( "MaskValue", 1 );
29   this->m_Parameters.SetReal( "Threshold", 0 );
30 }
31
32 // -------------------------------------------------------------------------
33 cpPluginsImageFilters::HistogramThresholdImageFilter::
34 ~HistogramThresholdImageFilter( )
35 {
36 }
37
38 // -------------------------------------------------------------------------
39 std::string cpPluginsImageFilters::HistogramThresholdImageFilter::
40 _GenerateData( )
41 {
42   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
43   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
44   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
45   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
46   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
47   return( r );
48 }
49
50 // -------------------------------------------------------------------------
51 template< class _TImage >
52 std::string cpPluginsImageFilters::HistogramThresholdImageFilter::
53 _GD0( _TImage* image )
54 {
55   if( image != NULL )
56     return( this->_GD1< _TImage, unsigned char >( image ) );
57   else
58     return(
59       "ImageFilters::HistogramThresholdImageFilter: No valid input image."
60       );
61 }
62
63 // -------------------------------------------------------------------------
64 template< class _TImage, class _TBinaryPixel >
65 std::string cpPluginsImageFilters::HistogramThresholdImageFilter::
66 _GD1( _TImage* image )
67 {
68   typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
69   typedef itk::HistogramThresholdImageFilter< _TImage, _TBinaryImage > _TFilter;
70
71   // Get parameters
72
73   // Configure filter
74   _TFilter* filter = this->_CreateITK< _TFilter >( );
75   filter->SetInput( image );
76   filter->Update( );
77
78   // Connect output
79   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
80   return( "HistogramThresholdImage: not complete yet." );
81 }
82
83 // eof - $RCSfile$