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