OpenWalnut  1.5.0dev
WSegmentationAlgoLevelSetCanny.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSEGMENTATIONALGOLEVELSETCANNY_H
26 #define WSEGMENTATIONALGOLEVELSETCANNY_H
27 
28 #ifdef OW_USE_ITK
29 
30 #include <string>
31 
32 #include "itkImage.h"
33 #include "itkCannySegmentationLevelSetImageFilter.h"
34 #include "itkGradientAnisotropicDiffusionImageFilter.h"
35 #include "itkCastImageFilter.h"
36 
37 #include "core/dataHandler/WITKImageConversion.h"
38 
39 #include "WSegmentationAlgo.h"
40 
41 /**
42  * Canny edge levelset segmentation.
43  * \class WSegmentationAlgoLevelSetCanny
44  * \note Work in progress.
45  */
46 class WSegmentationAlgoLevelSetCanny : public WSegmentationAlgo
47 {
48 public:
49  /**
50  * Standard constructor.
51  */
52  WSegmentationAlgoLevelSetCanny();
53 
54  /**
55  * Destructor.
56  */
57  virtual ~WSegmentationAlgoLevelSetCanny();
58 
59  /**
60  * Return the name of this algorithm.
61  * \return The name.
62  */
63  virtual std::string getName();
64 
65  /**
66  * Return a description of this algorithm.
67  * \return A description.
68  */
69  virtual std::string getDescription();
70 
71  /**
72  * Checks if any properties were changed.
73  * \return True, iff any properties were changed.
74  */
75  virtual bool propChanged();
76 
77  /**
78  * Implements the operation.
79  *
80  * \tparam The type of the values in the dataset's valueset.
81  * \param valueset The dataset's valueset.
82  * \return The resulting dataset.
83  */
84  template< typename T >
85  DataSetPtr operator() ( WValueSet< T > const* valueset ) const;
86 
87 private:
88  /**
89  * Initializes the algorithm's properties.
90  */
91  virtual void properties();
92 
93  /**
94  * A virtual function that calls the correct segmentation operation.
95  * \return The resulting dataset.
96  */
97  virtual DataSetPtr applyOperation();
98 
99  //! The number of iteration in the smoothing filter.
100  WPropInt m_smoothingIter;
101 
102  //! The conductance parameter for the anisotropic smoothing.
103  WPropDouble m_conductance;
104 
105  //! The levelset value.
106  WPropDouble m_level;
107 
108  //! The variance.
109  WPropDouble m_variance;
110 
111  //! A threshold.
112  WPropDouble m_threshold;
113 };
114 
115 template< typename T >
116 WSegmentationAlgo::DataSetPtr WSegmentationAlgoLevelSetCanny::operator() ( WValueSet< T > const* ) const
117 {
118  typedef itk::Image< T, 3 > ImgType;
119  typedef itk::Image< float, 3 > RealType;
120 
121  typedef itk::GradientAnisotropicDiffusionImageFilter< ImgType, RealType > SmoothingType;
122  typedef itk::CannySegmentationLevelSetImageFilter< RealType, RealType > CannyLSFilter;
123  typedef itk::CastImageFilter< ImgType, RealType > CastFilter;
124 
125  typename ImgType::Pointer image = makeImageFromDataSet< T >( m_dataSet );
126  typename SmoothingType::Pointer smoothing = SmoothingType::New();
127  typename CannyLSFilter::Pointer levelset = CannyLSFilter::New();
128  typename CastFilter::Pointer cast = CastFilter::New();
129 
130  smoothing->SetNumberOfIterations( m_smoothingIter->get( true ) );
131  smoothing->SetTimeStep( 0.0625 );
132  smoothing->SetConductanceParameter( m_conductance->get( true ) );
133  smoothing->SetInput( image );
134 
135  cast->SetInput( image );
136 
137  levelset->SetAdvectionScaling( 1.0 );
138  levelset->SetCurvatureScaling( 1.0 );
139  levelset->SetPropagationScaling( 0.0 );
140  levelset->SetMaximumRMSError( 0.01 );
141  levelset->SetNumberOfIterations( 10 );
142  levelset->SetThreshold( m_threshold->get( true ) / 100.0 );
143  levelset->SetVariance( m_variance->get( true ) );
144  levelset->SetIsoSurfaceValue( m_level->get( true ) );
145  levelset->SetInput( cast->GetOutput() );
146  levelset->SetFeatureImage( smoothing->GetOutput() );
147 
148  try
149  {
150  levelset->Update();
151  }
152  catch( ... )
153  {
154  throw WException( "Problem in Level Set Segmentation 1" );
155  }
156  return makeDataSetFromImage< float >( levelset->GetOutput() );
157 }
158 
159 #endif // OW_USE_ITK
160 
161 #endif // WSEGMENTATIONALGOLEVELSETCANNY_H
Basic exception handler.
Definition: WException.h:39
A base class for segmentation alorithms.
virtual void properties()=0
Initialize your algorithms properties here.
virtual std::string getName()=0
Return the name of this algorithm.
std::shared_ptr< WDataSetScalar > DataSetPtr
A conveniant typedef.
virtual DataSetPtr applyOperation()=0
A virtual function that calls the correct segmentation operation.
virtual bool propChanged()=0
Checks if any properties were changed.
virtual std::string getDescription()=0
Return a description of this algorithm.
Base Class for all value set types.
Definition: WValueSet.h:47