]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/MultiScaleGaussianImageFilter.cxx
...
[cpPlugins.git] / plugins / cpPluginsImageFilters / MultiScaleGaussianImageFilter.cxx
1 #include <cpPluginsImageFilters/MultiScaleGaussianImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_ITKInstances/ImageFilters.h>
4
5 #include <cpExtensions/Algorithms/MultiScaleGaussianImageFilter.h>
6 #include <cpExtensions/Algorithms/MultiScaleGaussianImageFilter.hxx>
7 #include <itkGradientRecursiveGaussianImageFilter.hxx>
8 #include <itkImageAdaptor.hxx>
9 #include <itkImageToImageFilter.hxx>
10 #include <itkInPlaceImageFilter.hxx>
11 #include <itkUnaryFunctorImageFilter.hxx>
12 #include <itkRecursiveGaussianImageFilter.hxx>
13 #include <itkImageConstIteratorWithIndex.hxx>
14 #include <itkRecursiveSeparableImageFilter.hxx>
15 #include <itkBinaryFunctorImageFilter.hxx>
16 #include <itkImageRegionConstIterator.hxx>
17 #include <itkImageScanlineIterator.hxx>
18 #include <itkImageSource.hxx>
19 #include <itkImageRegionIteratorWithIndex.hxx>
20 #include <itkImageScanlineConstIterator.hxx>
21 #include <itkImageRegionIterator.hxx>
22 #include <itkSimpleDataObjectDecorator.hxx>
23 #include <itkImageRegionConstIteratorWithIndex.hxx>
24 #include <itkNthElementPixelAccessor.h>
25 #include <itkImageBase.hxx>
26
27 // -------------------------------------------------------------------------
28 cpPluginsImageFilters::MultiScaleGaussianImageFilter::
29 MultiScaleGaussianImageFilter( )
30   : Superclass( )
31 {
32   this->_AddInput( "Input" );
33   this->_AddOutput< cpPlugins::Image >( "Output" );
34
35   this->m_Parameters.ConfigureAsRealList( "Sigmas" );
36
37   std::vector< std::string > choices;
38   choices.push_back( "float" );
39   choices.push_back( "double" );
40   this->m_Parameters.ConfigureAsChoices( "ScalarType", choices );
41   this->m_Parameters.SetSelectedChoice( "ScalarType", "float" );
42 }
43
44 // -------------------------------------------------------------------------
45 cpPluginsImageFilters::MultiScaleGaussianImageFilter::
46 ~MultiScaleGaussianImageFilter( )
47 {
48 }
49
50 // -------------------------------------------------------------------------
51 std::string cpPluginsImageFilters::MultiScaleGaussianImageFilter::
52 _GenerateData( )
53 {
54   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
55   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
56   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
57   return( r );
58 }
59
60 // -------------------------------------------------------------------------
61 template< class _TImage >
62 std::string cpPluginsImageFilters::MultiScaleGaussianImageFilter::
63 _GD0( _TImage* image )
64 {
65   if( image != NULL )
66   {
67     auto choice = this->m_Parameters.GetSelectedChoice( "ScalarType" );
68     if( choice == "float" )
69       return( this->_GD1< _TImage, float >( image ) );
70     else if( choice == "double" )
71       return( this->_GD1< _TImage, double >( image ) );
72     else return( "MultiScaleGaussianImageFilter: no valid scalar type." );
73   }
74   else
75     return(
76       "MultiScaleGaussianImageFilter: No valid input image."
77       );
78 }
79
80 // -------------------------------------------------------------------------
81 template< class _TImage, class _TScalar >
82 std::string cpPluginsImageFilters::MultiScaleGaussianImageFilter::
83 _GD1( _TImage* image )
84 {
85   typedef itk::CovariantVector< _TScalar, _TImage::ImageDimension > _TVector;
86   typedef itk::Image< _TVector, _TImage::ImageDimension > _TGradient;
87   typedef
88     cpExtensions::Algorithms::MultiScaleGaussianImageFilter< _TImage, _TGradient >
89     _TFilter;
90
91   auto sigmas = this->m_Parameters.GetRealList( "Sigmas" );
92   if( sigmas.size( ) == 0 )
93     return(
94       "MultiScaleGaussianImageFilter: No given sigmas."
95       );
96
97   // Configure filter
98   _TFilter* filter = this->_CreateITK< _TFilter >( );
99   filter->SetInput( image );
100   for( auto sIt = sigmas.begin( ); sIt != sigmas.end( ); ++sIt )
101     filter->AddScale( *sIt );
102   filter->Update( );
103
104   // Connect output
105   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
106   return( "" );
107 }
108
109 // eof - $RCSfile$