]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/MoriLabelling.h
...
[FrontAlgorithms.git] / appli / CTBronchi / MoriLabelling.h
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__MoriLabelling__h__
6 #define __CTBronchi__MoriLabelling__h__
7
8 #include <itkStatisticsImageFilter.h>
9 #include <fpa/Filters/BaseMarksInterface.h>
10 #include <fpa/Filters/Image/SeedsFromLabelsInterface.h>
11 #include <fpa/Filters/Image/DefaultTraits.h>
12 #include <fpa/Filters/Image/RegionGrow.h>
13 #include <fpa/Functors/RegionGrow/BinaryThreshold.h>
14
15 namespace CTBronchi
16 {
17   /**
18    */
19   template< class _TImage, class _TLabels >
20   class MoriLabellingTraits
21     : public fpa::Filters::Image::DefaultTraits< _TImage, _TLabels, typename _TLabels::PixelType >
22   {
23   public:
24     typedef fpa::Filters::Image::DefaultTraits< _TImage, _TLabels, typename _TLabels::PixelType > Superclass;
25     typedef typename Superclass::TInternalTraits  TInternalTraits;
26     typedef typename Superclass::TMarksImage      TMarksImage;
27     typedef typename Superclass::TFilterInterface TFilterInterface;
28
29     typedef fpa::Filters::BaseMarksInterface< TInternalTraits >  TMarksInterface;
30     typedef fpa::Filters::Image::SeedsFromLabelsInterface< TInternalTraits > TSeedsInterface;
31   };
32
33   /**
34    */
35   template< class _TImage, class _TLabels, class _TScalarImage >
36   class MoriLabelling
37     : public fpa::Filters::Image::RegionGrow< _TImage, _TLabels, typename _TLabels::PixelType, CTBronchi::MoriLabellingTraits< _TImage, _TLabels > >
38   {
39   public:
40     typedef CTBronchi::MoriLabellingTraits< _TImage, _TLabels > TTraits;
41     fpaTraitsMacro( typename TTraits );
42
43     typedef fpa::Filters::Image::RegionGrow< _TImage, _TLabels, TMark, TTraits > Superclass;
44     typedef MoriLabelling Self;
45     typedef itk::SmartPointer< Self > Pointer;
46     typedef itk::SmartPointer< const Self > ConstPointer;
47
48     typedef fpa::Functors::RegionGrow::BinaryThreshold< TInputValue > TFunctor;
49
50   public:
51     itkNewMacro( Self );
52     itkTypeMacro( MoriLabelling, fpa::Filters::Image::RegionGrow );
53
54     itkGetConstMacro( VesselnessThreshold, double );
55     itkSetMacro( VesselnessThreshold, double );
56
57     itkGetConstMacro( UpperThreshold, TInputValue );
58     itkSetMacro( UpperThreshold, TInputValue );
59
60     ivqITKInputMacro( InputLabels, _TLabels );
61     ivqITKInputMacro( InputVesselness, _TScalarImage );
62
63   protected:
64     MoriLabelling( )
65       : Superclass( ),
66         m_VesselnessThreshold( 5 ),
67         m_UpperThreshold( -650 )
68       {
69         ivqITKInputConfigureMacro( InputLabels, _TLabels );
70         ivqITKInputConfigureMacro( InputVesselness, _TScalarImage );
71         this->m_Functor = TFunctor::New( );
72         this->SetPredicate( this->m_Functor );
73       }
74
75     virtual ~MoriLabelling( )
76       {
77       }
78
79     virtual const itk::DataObject* _GetReferenceInput( ) const override
80       {
81         return( this->GetInputLabels( ) );
82       }
83     virtual void _BeforeGenerateData( ) override
84       {
85         this->Superclass::_BeforeGenerateData( );
86
87         this->m_Functor->SetUpperThreshold( this->m_UpperThreshold );
88
89         typedef itk::StatisticsImageFilter< _TScalarImage > _TStats;
90         typename _TStats::Pointer stats = _TStats::New( );
91         stats->SetInput( this->GetInputVesselness( ) );
92         stats->Update( );
93         double vAvg = double( stats->GetMean( ) );
94         double vStd = double( stats->GetSigma( ) );
95         double vMin = double( stats->GetMinimum( ) );
96         double vMax = double( stats->GetMaximum( ) );
97         std::exit( 1 );
98         /* TODO
99            this->m_MinVesselness =
100            ( this->m_VesselnessThreshold / double( 100 ) ) *
101            double( stats->GetMaximum( ) );
102         */
103       }
104
105     virtual void _PostComputeOutputValue( TNode& n ) override
106       {
107         this->Superclass::_PostComputeOutputValue( n );
108         if( n.Value == this->GetInsideValue( ) )
109         {
110           const _TLabels* labels = this->GetInputLabels( );
111           const _TScalarImage* vesselness = this->GetInputVesselness( );
112           if( labels->GetPixel( n.Vertex ) == 0 )
113           {
114             if( this->m_MinVesselness < vesselness->GetPixel( n.Vertex ) )
115               n.Value = this->GetInsideValue( );
116             else
117               n.Value = 0;
118
119           } // fi
120
121         } // fi
122       }
123
124   private:
125     // Purposely not implemented.
126     MoriLabelling( const Self& other );
127     Self& operator=( const Self& other );
128
129   protected:
130     typename TFunctor::Pointer m_Functor;
131     double m_VesselnessThreshold;
132     double m_MinVesselness;
133     TInputValue m_UpperThreshold;
134   };
135
136 } // ecapseman
137
138 #endif // __CTBronchi__Functions__h__
139
140 // eof - $RCSfile$