]> Creatis software - FrontAlgorithms.git/blob - appli/CTArteries/algorithms/RandomWalkSegmentation.h
b7199decdaee3ce4fbe5f0c751c1fd884a2b0f54
[FrontAlgorithms.git] / appli / CTArteries / algorithms / RandomWalkSegmentation.h
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __RandomWalkSegmentation__h__
5 #define __RandomWalkSegmentation__h__
6
7 #include <itkImageToImageFilter.h>
8 #include <fpa/Config.h>
9 #include <fpa/DataStructures/Image/Path.h>
10
11 /**
12  */
13 template< class _TInputImage, class _TOutputImage >
14 class RandomWalkSegmentation
15   : public itk::ImageToImageFilter< _TInputImage, _TOutputImage >
16 {
17 public:
18   typedef _TInputImage  TInputImage;
19   typedef _TOutputImage TOutputImage;
20
21   typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
22   typedef RandomWalkSegmentation        Self;
23   typedef itk::SmartPointer< Self >       Pointer;
24   typedef itk::SmartPointer< const Self > ConstPointer;
25
26   typedef typename TInputImage::IndexType TIndex;
27   typedef typename TInputImage::PointType TPoint;
28
29   struct TSeed
30   {
31     TIndex Index;
32     TPoint Point;
33     bool IsPoint;
34   };
35   typedef fpa::DataStructures::Image::Path< TInputImage::ImageDimension > TPath;
36
37 public:
38   itkNewMacro( Self );
39   itkTypeMacro( RandomWalkSegmentation, itk::ImageToImageFilter );
40
41   itkGetConstMacro( StartSeed, TSeed );
42   itkGetConstMacro( EndSeed, TSeed );
43
44   itkGetConstMacro( Beta, double );
45   itkSetMacro( Beta, double );
46
47   itkGetConstMacro( Sigma, double );
48   itkSetMacro( Sigma, double );
49
50   itkGetConstMacro( Radius, double );
51   itkSetMacro( Radius, double );
52
53   fpaFilterOutputMacro( OutputAxis, TPath );
54
55 public:
56   void AddSeed( const TIndex& s );
57   void AddSeed( const TPoint& s );
58   void ClearSeeds( );
59   unsigned long GetNumberOfSeeds( ) const;
60
61   void SetStartSeed( const TIndex& s );
62   void SetStartSeed( const TPoint& s );
63
64   void SetEndSeed( const TIndex& s );
65   void SetEndSeed( const TPoint& s );
66
67 protected:
68   RandomWalkSegmentation( );
69   virtual ~RandomWalkSegmentation( );
70
71   virtual void GenerateData( ) override;
72
73 private:
74   template< class _TIn, class _TSeed >
75   void _SynchSeed( const _TIn* in, _TSeed& seed );
76
77   template< class _TIn, class _TOutPtr >
78   void _Smooth( const _TIn* in, _TOutPtr& out, double s );
79
80   template< class _TIn, class _TOutPtr, class _TAxisPtr, class _TSeeds >
81   typename _TIn::RegionType _RawSegmentation(
82     const _TIn* in, const _TSeeds& seeds,
83     const typename _TIn::IndexType& s0,
84     const typename _TIn::IndexType& s1,
85     const typename _TOutPtr::ObjectType::PixelType& beta,
86     _TOutPtr& out, _TAxisPtr& out_axis,
87     typename _TOutPtr::ObjectType::PixelType& oMean,
88     typename _TOutPtr::ObjectType::PixelType& oSTD
89     );
90
91   template< class _TIn, class _TOutPtr >
92   typename _TIn::RegionType _ROI(
93     const _TIn* in, const typename _TIn::RegionType& roi, unsigned int pad,
94     _TOutPtr& out
95     );
96
97   template< class _TAxisPtr, class _TRegion >
98   void _AxisROI(
99     const typename _TAxisPtr::ObjectType* in, const _TRegion& roi,
100     _TAxisPtr& out
101     );
102
103   template< class _TInRaw, class _TInCosts, class _TAxis, class _TScalar, class _TOutPtr >
104   void _Label(
105     const _TInRaw* raw, const _TInCosts* costs, const _TAxis* axis,
106     const _TScalar& mean, const _TScalar& dev, const _TScalar& radius,
107     _TOutPtr& out
108     );
109
110   template< class _TIn, class _TOutPtr >
111   void _RandomWalker(
112     const _TIn* in, const typename _TOutPtr::ObjectType* labels,
113     const typename _TIn::PixelType& beta,
114     _TOutPtr& out
115     );
116
117   template< class _TIn, class _TSeeds, class _TSeed, class _TOutPtr, class _TAxisPtr >
118   void _DistanceAndAxis(
119     const _TIn* in, const _TSeeds& seeds,
120     const _TSeed& p0, const _TSeed& p1,
121     _TOutPtr& out_dist, _TAxisPtr& out_axis
122     );
123
124   template< class _TInPtr >
125   void _Save( const _TInPtr& in, const std::string& fname );
126
127 private:
128   // Purposely not implemented
129   RandomWalkSegmentation( const Self& other );
130   Self& operator=( const Self& other );
131
132 protected:
133   TSeed m_StartSeed;
134   TSeed m_EndSeed;
135   std::vector< TSeed > m_Seeds;
136
137   double m_Beta;
138   double m_Sigma;
139   double m_Radius;
140 };
141
142 #ifndef ITK_MANUAL_INSTANTIATION
143 #  include "RandomWalkSegmentation.hxx"
144 #endif // ITK_MANUAL_INSTANTIATION
145
146 #endif // __RandomWalkSegmentation__h__
147
148 // eof - $RCSfile$