1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__MoriLabelling__hxx__
6 #define __CTBronchi__MoriLabelling__hxx__
8 // -------------------------------------------------------------------------
9 template< class _TInputImage, class _TLabelImage >
10 typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
11 TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
12 GetUpperThreshold( ) const
14 return( this->m_Functor->GetUpperThreshold( ) );
17 // -------------------------------------------------------------------------
18 template< class _TInputImage, class _TLabelImage >
19 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
20 SetUpperThreshold( TInputValue t )
22 this->m_Functor->SetUpperThreshold( t );
25 // -------------------------------------------------------------------------
26 template< class _TInputImage, class _TLabelImage >
27 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
30 m_LastThreshold( TInputValue( 0 ) )
32 fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
33 this->m_Functor = TFunctor::New( );
34 this->SetPredicate( this->m_Functor );
37 // -------------------------------------------------------------------------
38 template< class _TInputImage, class _TLabelImage >
39 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
44 // -------------------------------------------------------------------------
45 template< class _TInputImage, class _TLabelImage >
46 const itk::DataObject*
47 CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
48 _GetReferenceInput( ) const
50 return( this->GetInputLabels( ) );
53 // -------------------------------------------------------------------------
54 template< class _TInputImage, class _TLabelImage >
55 void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
56 _PostComputeOutputValue( TNode& n )
58 this->Superclass::_PostComputeOutputValue( n );
59 if( n.Value == this->GetInsideValue( ) )
61 const _TInputImage* input = this->GetInput( );
62 const TLabelImage* labels = this->GetInputLabels( );
63 double x = input->GetPixel( n.Vertex );
65 double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
66 double b = std::fabs( x - double( this->m_LastThreshold ) );
68 if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
74 // -------------------------------------------------------------------------
77 template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
80 const _TInputPtr& input, const _TOutputPtr& input_labels,
81 const _TInputValue& last_thr,
82 std::map< std::string, std::string >& args
85 typedef typename _TInputPtr::ObjectType _TInput;
86 typedef typename _TOutputPtr::ObjectType _TOutput;
87 typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
89 typename _TLabelling::Pointer labelling = _TLabelling::New( );
90 labelling->SetInput( input );
91 labelling->SetInputLabels( input_labels );
92 labelling->SetOutsideValue( 2 );
93 labelling->SetInsideValue( 1 );
94 labelling->SetUpperThreshold(
95 _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
97 labelling->SetLastThreshold( last_thr );
98 double t = MeasureTime( labelling );
99 std::cout << "Labelling executed in " << t << " s" << std::endl;
100 output = labelling->GetOutput( );
101 std::map< std::string, std::string >::const_iterator i =
102 args.find( "out_labels" );
103 if( i != args.end( ) )
104 WriteImage( output, i->second );
105 output->DisconnectPipeline( );
109 #endif // __CTBronchi__MoriLabelling__hxx__