1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __RandomWalkerLabelling__hxx__
5 #define __RandomWalkerLabelling__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
11 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
12 SetInputImage( const TRawImage* i )
17 // -------------------------------------------------------------------------
18 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
19 typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
20 TLabelsImage* RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
23 return( this->GetOutput( ) );
26 // -------------------------------------------------------------------------
27 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
28 const typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
29 TLabelsImage* RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
30 GetOutputLabels( ) const
32 return( this->GetOutput( ) );
35 // -------------------------------------------------------------------------
36 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
37 typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
38 TLabel RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
39 GetOutsideLabel( ) const
41 return( this->GetInitValue( ) );
44 // -------------------------------------------------------------------------
45 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
46 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
47 SetOutsideLabel( const TLabel& v )
49 this->SetInitValue( v );
52 // -------------------------------------------------------------------------
53 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
54 RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
55 RandomWalkLabelling( )
57 m_InsideLabel( TLabel( 1 ) ),
58 m_LowerLabel( TLabel( 3 ) ),
59 m_UpperLabel( TLabel( 4 ) ),
60 m_Radius( double( 1 ) ),
61 m_LowerThreshold( double( 0 ) ),
62 m_UpperThreshold( double( 0 ) ),
63 m_MaxCost( std::numeric_limits< TScalar >::max( ) )
65 fpaFilterInputConfigureMacro( InputCosts, TCostsImage );
66 fpaFilterInputConfigureMacro( InputPath, TPath );
67 this->SetOutsideLabel( TLabel( 2 ) );
70 // -------------------------------------------------------------------------
71 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
72 RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
73 ~RandomWalkLabelling( )
77 // -------------------------------------------------------------------------
78 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
79 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
80 _PrepareSeeds( const itk::DataObject* reference )
82 const TPath* path = this->GetInputPath( );
83 if( path->GetSize( ) > 0 )
86 node.Vertex = node.Parent = path->GetVertex( 0 );
88 this->m_UnifiedSeeds.clear( );
89 this->m_UnifiedSeeds.insert( node );
95 // -------------------------------------------------------------------------
96 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
97 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
98 _PostComputeOutputValue( TNode& n )
100 const TRawImage* raw = this->GetInput( );
101 const TCostsImage* costs = this->GetInputCosts( );
102 const TPath* path = this->GetInputPath( );
105 raw->TransformIndexToPhysicalPoint( path->GetVertex( this->m_CurrIdx ), c );
106 raw->TransformIndexToPhysicalPoint( n.Vertex, p );
107 double d = double( c.EuclideanDistanceTo( p ) );
108 if( d <= this->m_Radius )
111 if( costs->GetPixel( n.Vertex ) == this->m_MaxCost )
113 double v = double( raw->GetPixel( n.Vertex ) );
114 if( v <= this->m_LowerThreshold )
115 n.Value = this->GetLowerLabel( );
116 else if( v >= this->m_UpperThreshold )
117 n.Value = this->GetUpperLabel( );
119 n.Value = TLabel( 0 );
122 n.Value = this->GetInsideLabel( );
126 n.Value = this->GetOutsideLabel( );
132 // -------------------------------------------------------------------------
133 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
134 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
137 const TPath* path = this->GetInputPath( );
139 this->_GetMark( path->GetVertex( this->m_CurrIdx ) ) > 0 &&
140 this->m_CurrIdx < path->GetSize( )
142 this->m_CurrIdx += 1;
143 if( this->m_CurrIdx < path->GetSize( ) )
146 node.Vertex = node.Parent = path->GetVertex( this->m_CurrIdx );
148 this->_QueuePush( node );
153 #endif // __RandomWalkLabelling__hxx__