1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __CTBronchi__MoriLabelling__hxx__
7 #define __CTBronchi__MoriLabelling__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TInputImage, class _TLabelImage >
11 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
12 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
13 GetUpperThreshold( ) const
15 return( this->m_Functor->GetUpperThreshold( ) );
18 // -------------------------------------------------------------------------
19 template< class _TInputImage, class _TLabelImage >
20 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
21 SetUpperThreshold( TInputValue t )
23 this->m_Functor->SetUpperThreshold( t );
26 // -------------------------------------------------------------------------
27 template< class _TInputImage, class _TLabelImage >
28 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
31 m_LastThreshold( TInputValue( 0 ) )
33 fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
34 this->m_Functor = TFunctor::New( );
35 this->SetPredicate( this->m_Functor );
38 // -------------------------------------------------------------------------
39 template< class _TInputImage, class _TLabelImage >
40 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
45 // -------------------------------------------------------------------------
46 template< class _TInputImage, class _TLabelImage >
47 const itk::DataObject*
48 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
49 _GetReferenceInput( ) const
51 return( this->GetInputLabels( ) );
54 // -------------------------------------------------------------------------
55 template< class _TInputImage, class _TLabelImage >
56 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
57 _PostComputeOutputValue( TNode& n )
59 this->Superclass::_PostComputeOutputValue( n );
60 if( n.Value == this->GetInsideValue( ) )
62 const _TInputImage* input = this->GetInput( );
63 const TLabelImage* labels = this->GetInputLabels( );
64 double x = input->GetPixel( n.Vertex );
66 double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
67 double b = std::fabs( x - double( this->m_LastThreshold ) );
69 if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
75 // -------------------------------------------------------------------------
78 template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
81 const _TInputPtr& input, const _TOutputPtr& input_labels,
82 const _TInputValue& last_thr,
83 std::map< std::string, std::string >& args
86 typedef typename _TInputPtr::ObjectType _TInput;
87 typedef typename _TOutputPtr::ObjectType _TOutput;
88 typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
90 typename _TLabelling::Pointer labelling = _TLabelling::New( );
91 labelling->SetInput( input );
92 labelling->SetInputLabels( input_labels );
93 labelling->SetOutsideValue( 2 );
94 labelling->SetInsideValue( 1 );
95 labelling->SetUpperThreshold(
96 _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
98 labelling->SetLastThreshold( last_thr );
99 double t = MeasureTime( labelling );
100 std::cout << "Labelling executed in " << t << " s" << std::endl;
101 output = labelling->GetOutput( );
102 std::map< std::string, std::string >::const_iterator i =
103 args.find( "out_labels" );
104 if( i != args.end( ) )
105 WriteImage( output, i->second );
106 output->DisconnectPipeline( );
111 #endif // __CTBronchi__MoriLabelling__hxx__