]> 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
98         this->m_MinVesselness = vAvg + ( vStd * double( 5 ) );
99         /* TODO
100            std::cout
101            << vAvg << std::endl
102            << vStd << std::endl
103            << vMin << std::endl
104            << vMax << std::endl;
105
106            std::cout
107            << ( this->m_VesselnessThreshold / double( 100 ) ) * double( vMax )
108            << std::endl
109            << vAvg + ( vStd * double( 3 ) ) << std::endl;
110
111            std::exit( 1 );
112         */
113         /* TODO
114            this->m_MinVesselness =
115            ( this->m_VesselnessThreshold / double( 100 ) ) *
116            double( stats->GetMaximum( ) );
117         */
118       }
119
120     virtual void _PostComputeOutputValue( TNode& n ) override
121       {
122         this->Superclass::_PostComputeOutputValue( n );
123         if( n.Value == this->GetInsideValue( ) )
124         {
125           const _TLabels* labels = this->GetInputLabels( );
126           const _TScalarImage* vesselness = this->GetInputVesselness( );
127           if( labels->GetPixel( n.Vertex ) == 0 )
128           {
129             if( this->m_MinVesselness < vesselness->GetPixel( n.Vertex ) )
130               n.Value = this->GetInsideValue( );
131             else
132               n.Value = 0;
133
134           } // fi
135
136         } // fi
137       }
138
139   private:
140     // Purposely not implemented.
141     MoriLabelling( const Self& other );
142     Self& operator=( const Self& other );
143
144   protected:
145     typename TFunctor::Pointer m_Functor;
146     double m_VesselnessThreshold;
147     double m_MinVesselness;
148     TInputValue m_UpperThreshold;
149   };
150
151 } // ecapseman
152
153 #endif // __CTBronchi__Functions__h__
154
155 // eof - $RCSfile$