#ifndef __CTBronchi__MoriLabelling__hxx__
#define __CTBronchi__MoriLabelling__hxx__
-#include <itkImageRegionConstIterator.h>
-#include <itkImageRegionIterator.h>
-
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
-const _TLabelImage*
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputLabelImage( ) const
+typename CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+TInputValue CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+GetUpperThreshold( ) const
{
- return( this->GetInput( ) );
+ return( this->m_Functor->GetUpperThreshold( ) );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputLabelImage( TLabelImage* image )
+SetUpperThreshold( TInputValue t )
{
- this->SetInput( image );
+ this->m_Functor->SetUpperThreshold( t );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
-const _TInputImage*
CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-GetInputRawImage( ) const
+MoriLabelling( )
+ : Superclass( ),
+ m_LastThreshold( TInputValue( 0 ) )
{
- return(
- dynamic_cast< const TInputImage* >(
- this->itk::ProcessObject::GetInput( 1 )
- )
- );
+ fpaFilterInputConfigureMacro( InputLabels, TLabelImage );
+ this->m_Functor = TFunctor::New( );
+ this->SetPredicate( this->m_Functor );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-SetInputRawImage( TInputImage* image )
+CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+~MoriLabelling( )
{
- this->itk::ProcessObject::SetNthInput( 1, image );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
+const itk::DataObject*
CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-MoriLabelling( )
- : Superclass( ),
- m_UpperThreshold( TLabel( 0 ) ),
- m_InsideValue( TLabel( 0 ) ),
- m_InsideLabel( TLabel( 0 ) ),
- m_OutsideLabel( TLabel( 0 ) )
+_GetReferenceInput( ) const
{
- this->SetNumberOfRequiredInputs( 2 );
+ return( this->GetInputLabels( ) );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TLabelImage >
-CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-~MoriLabelling( )
+void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
+_PostComputeOutputValue( TNode& n )
{
+ this->Superclass::_PostComputeOutputValue( n );
+ if( n.Value == this->GetInsideValue( ) )
+ {
+ const _TInputImage* input = this->GetInput( );
+ const TLabelImage* labels = this->GetInputLabels( );
+ double x = input->GetPixel( n.Vertex );
+ /* TODO
+ double a = std::fabs( x - double( this->m_Functor->GetUpperThreshold( ) ) );
+ double b = std::fabs( x - double( this->m_LastThreshold ) );
+ */
+ if( labels->GetPixel( n.Vertex ) == 0 /* && b < a*/ )
+ n.Value = 0;
+
+ } // fi
}
// -------------------------------------------------------------------------
-template< class _TInputImage, class _TLabelImage >
-void CTBronchi::MoriLabelling< _TInputImage, _TLabelImage >::
-ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
+namespace CTBronchi
{
- itk::ImageRegionConstIterator< TLabelImage >
- lIt( this->GetInputLabelImage( ), region );
- itk::ImageRegionConstIterator< TInputImage >
- iIt( this->GetInputRawImage( ), region );
- itk::ImageRegionIterator< TLabelImage >
- oIt( this->GetOutput( ), region );
-
- lIt.GoToBegin( );
- iIt.GoToBegin( );
- oIt.GoToBegin( );
- while( !( lIt.IsAtEnd( ) || iIt.IsAtEnd( ) || oIt.IsAtEnd( ) ) )
+ template< class _TInputPtr, class _TOutputPtr, class _TInputValue >
+ void Label(
+ _TOutputPtr& output,
+ const _TInputPtr& input, const _TOutputPtr& input_labels,
+ const _TInputValue& last_thr,
+ std::map< std::string, std::string >& args
+ )
{
- if( lIt.Get( ) != this->m_InsideValue )
- {
- if( this->m_UpperThreshold < iIt.Get( ) )
- oIt.Set( this->m_OutsideLabel );
- else
- oIt.Set( TLabel( 0 ) );
- }
- else
- oIt.Set( this->m_InsideLabel );
- ++lIt;
- ++iIt;
- ++oIt;
+ typedef typename _TInputPtr::ObjectType _TInput;
+ typedef typename _TOutputPtr::ObjectType _TOutput;
+ typedef CTBronchi::MoriLabelling< _TInput, _TOutput > _TLabelling;
- } // elihw
-}
+ typename _TLabelling::Pointer labelling = _TLabelling::New( );
+ labelling->SetInput( input );
+ labelling->SetInputLabels( input_labels );
+ labelling->SetOutsideValue( 2 );
+ labelling->SetInsideValue( 1 );
+ labelling->SetUpperThreshold(
+ _TInputValue( std::atof( args[ "labelling_upper_threshold" ].c_str( ) ) )
+ );
+ labelling->SetLastThreshold( last_thr );
+ double t = MeasureTime( labelling );
+ std::cout << "Labelling executed in " << t << " s" << std::endl;
+ output = labelling->GetOutput( );
+ std::map< std::string, std::string >::const_iterator i =
+ args.find( "out_labels" );
+ if( i != args.end( ) )
+ WriteImage( output, i->second );
+ output->DisconnectPipeline( );
+ }
+
+} // ecapseman
#endif // __CTBronchi__MoriLabelling__hxx__