1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __RandomWalkerLabelling__hxx__
5 #define __RandomWalkerLabelling__hxx__
7 // -------------------------------------------------------------------------
8 template< class _TRawImage, class _TLabelsImage >
9 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
10 SetInputImage( const TRawImage* i )
15 // -------------------------------------------------------------------------
16 template< class _TRawImage, class _TLabelsImage >
17 typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
18 TLabelsImage* RandomWalkLabelling< _TRawImage, _TLabelsImage >::
21 return( this->GetOutput( ) );
24 // -------------------------------------------------------------------------
25 template< class _TRawImage, class _TLabelsImage >
26 const typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
27 TLabelsImage* RandomWalkLabelling< _TRawImage, _TLabelsImage >::
28 GetOutputLabels( ) const
30 return( this->GetOutput( ) );
33 // -------------------------------------------------------------------------
34 template< class _TRawImage, class _TLabelsImage >
35 typename RandomWalkLabelling< _TRawImage, _TLabelsImage >::
36 TLabel RandomWalkLabelling< _TRawImage, _TLabelsImage >::
37 GetOutsideLabel( ) const
39 return( this->GetInitValue( ) );
42 // -------------------------------------------------------------------------
43 template< class _TRawImage, class _TLabelsImage >
44 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
45 SetOutsideLabel( const TLabel& v )
47 this->SetInitValue( v );
50 // -------------------------------------------------------------------------
51 template< class _TRawImage, class _TLabelsImage >
52 RandomWalkLabelling< _TRawImage, _TLabelsImage >::
53 RandomWalkLabelling( )
55 m_InsideLabel( TLabel( 1 ) ),
56 m_LowerLabel( TLabel( 3 ) ),
57 m_UpperLabel( TLabel( 4 ) ),
58 m_Radius( double( 1 ) ),
59 m_LowerThreshold( double( 0 ) ),
60 m_UpperThreshold( double( 0 ) )
62 fpaFilterInputConfigureMacro( InputMarks, TLabelsImage );
63 fpaFilterInputConfigureMacro( InputPath, TPath );
64 this->SetOutsideLabel( TLabel( 2 ) );
67 // -------------------------------------------------------------------------
68 template< class _TRawImage, class _TLabelsImage >
69 RandomWalkLabelling< _TRawImage, _TLabelsImage >::
70 ~RandomWalkLabelling( )
74 // -------------------------------------------------------------------------
75 template< class _TRawImage, class _TLabelsImage >
76 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
77 _PrepareSeeds( const itk::DataObject* reference )
79 const TPath* path = this->GetInputPath( );
80 if( path->GetSize( ) > 0 )
83 node.Vertex = node.Parent = path->GetVertex( 0 );
85 this->m_UnifiedSeeds.clear( );
86 this->m_UnifiedSeeds.insert( node );
92 // -------------------------------------------------------------------------
93 template< class _TRawImage, class _TLabelsImage >
94 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
95 _PostComputeOutputValue( TNode& n )
97 const TRawImage* raw = this->GetInput( );
98 const TLabelsImage* labels = this->GetInputMarks( );
99 const TPath* path = this->GetInputPath( );
102 raw->TransformIndexToPhysicalPoint( path->GetVertex( this->m_CurrIdx ), c );
103 raw->TransformIndexToPhysicalPoint( n.Vertex, p );
104 double d = double( c.EuclideanDistanceTo( p ) );
105 if( d <= this->m_Radius )
108 if( labels->GetPixel( n.Vertex ) == 0 )
110 double v = double( raw->GetPixel( n.Vertex ) );
111 if( v <= this->m_LowerThreshold )
112 n.Value = this->GetLowerLabel( );
113 else if( v >= this->m_UpperThreshold )
114 n.Value = this->GetUpperLabel( );
116 n.Value = TLabel( 0 );
119 n.Value = this->GetInsideLabel( );
123 n.Value = this->GetOutsideLabel( );
129 // -------------------------------------------------------------------------
130 template< class _TRawImage, class _TLabelsImage >
131 void RandomWalkLabelling< _TRawImage, _TLabelsImage >::
134 const TPath* path = this->GetInputPath( );
136 this->_GetMark( path->GetVertex( this->m_CurrIdx ) ) > 0 &&
137 this->m_CurrIdx < path->GetSize( )
139 this->m_CurrIdx += 1;
140 if( this->m_CurrIdx < path->GetSize( ) )
143 node.Vertex = node.Parent = path->GetVertex( this->m_CurrIdx );
145 this->_QueuePush( node );
150 #endif // __RandomWalkLabelling__hxx__