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 );
50 this->SetFillValue( v );
53 // -------------------------------------------------------------------------
54 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
55 RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
56 RandomWalkLabelling( )
58 m_InsideLabel( TLabel( 1 ) ),
59 m_LowerLabel( TLabel( 3 ) ),
60 m_UpperLabel( TLabel( 4 ) ),
61 m_Radius( double( 1 ) ),
62 m_LowerThreshold( double( 0 ) ),
63 m_UpperThreshold( double( 0 ) ),
64 m_MaxCost( std::numeric_limits< TScalar >::max( ) )
66 fpaFilterInputConfigureMacro( InputCosts, TCostsImage );
67 fpaFilterInputConfigureMacro( InputPath, TPath );
68 this->SetOutsideLabel( TLabel( 2 ) );
71 // -------------------------------------------------------------------------
72 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
73 RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
74 ~RandomWalkLabelling( )
78 // -------------------------------------------------------------------------
79 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
80 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
81 _PrepareSeeds( const itk::DataObject* reference )
83 const TPath* path = this->GetInputPath( );
84 if( path->GetSize( ) > 0 )
87 node.Vertex = node.Parent = path->GetVertex( 0 );
89 this->m_UnifiedSeeds.clear( );
90 this->m_UnifiedSeeds.insert( node );
96 // -------------------------------------------------------------------------
97 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
98 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
99 _PostComputeOutputValue( TNode& n )
101 const TRawImage* raw = this->GetInput( );
102 const TCostsImage* costs = this->GetInputCosts( );
103 const TPath* path = this->GetInputPath( );
106 raw->TransformIndexToPhysicalPoint( path->GetVertex( this->m_CurrIdx ), c );
107 raw->TransformIndexToPhysicalPoint( n.Vertex, p );
108 double d = double( c.EuclideanDistanceTo( p ) );
109 if( d <= this->m_Radius )
112 if( costs->GetPixel( n.Vertex ) == this->m_MaxCost )
114 double v = double( raw->GetPixel( n.Vertex ) );
115 if( v < this->m_LowerThreshold )
116 n.Value = this->GetLowerLabel( );
117 else if( this->m_UpperThreshold < v )
118 n.Value = this->GetUpperLabel( );
120 n.Value = TLabel( 0 );
123 n.Value = this->GetInsideLabel( );
127 n.Value = this->GetOutsideLabel( );
133 // -------------------------------------------------------------------------
134 template< class _TRawImage, class _TCostsImage, class _TLabelsImage >
135 void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >::
138 const TPath* path = this->GetInputPath( );
139 if( this->m_CurrIdx < path->GetSize( ) )
142 this->_GetMark( path->GetVertex( this->m_CurrIdx ) ) > 0 &&
143 this->m_CurrIdx < path->GetSize( )
145 this->m_CurrIdx += 1;
146 if( this->m_CurrIdx < path->GetSize( ) )
149 node.Vertex = node.Parent = path->GetVertex( this->m_CurrIdx );
151 this->_QueuePush( node );
158 #endif // __RandomWalkLabelling__hxx__