]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx
f3addf451c0a00a0b1545ce1ee014b8369a1f99e
[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(
57       this->_GD1< _TImage, itk::Image< unsigned char, _TImage::ImageDimension > >( image )
58       );
59   else
60     return(
61       "ImageFilters::HistogramThresholdImageFilter: No valid input image."
62       );
63 }
64
65 // -------------------------------------------------------------------------
66 template< class _TImage, class _TBinaryImage >
67 std::string cpPluginsImageFilters::HistogramThresholdImageFilter::
68 _GD1( _TImage* image )
69 {
70   typedef itk::HistogramThresholdImageFilter< _TImage, _TBinaryImage > _F;
71   typedef typename _TImage::PixelType _TP;
72   typedef typename _TBinaryImage::PixelType _UP;
73
74   // Get parameters
75
76   // Configure filter
77   _F* filter = this->_CreateITK< _F >( );
78   filter->SetInput( image );
79   filter->Update( );
80
81   // Connect output
82   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
83   return( "HistogramThresholdImage: not complete yet." );
84 }
85
86 // eof - $RCSfile$