1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__Mori__h__
6 #define __CTBronchi__Mori__h__
9 #include <CTBronchi/Functions.h>
10 #include <fpa/Filters/Image/Mori.h>
14 // -----------------------------------------------------------------------
15 template< class _TInputPtr, class _TOutputPtr, class _TSeed >
16 typename _TInputPtr::ObjectType::PixelType Mori(
17 _TOutputPtr& output, const _TInputPtr& input, _TSeed& seed,
18 std::map< std::string, std::string >& args
21 typedef typename _TInputPtr::ObjectType _TInput;
22 typedef typename _TOutputPtr::ObjectType _TOutput;
23 typedef fpa::Filters::Image::Mori< _TInput, _TOutput > _TMori;
24 typedef typename _TInput::PixelType _TInputPixel;
25 typedef typename _TOutput::PixelType _TOutputPixel;
27 _TOutputPixel i_val = _TOutputPixel( 1 );
28 _TOutputPixel o_val = _TOutputPixel( 0 );
30 typename _TMori::Pointer mori = _TMori::New( );
31 mori->SetInput( input );
32 mori->SetSeed( seed );
33 mori->SetInsideValue( i_val );
34 mori->SetOutsideValue( o_val );
35 mori->SetMinimumThreshold(
36 _TInputPixel( std::atof( args[ "mori_minimum_threshold" ].c_str( ) ) )
38 mori->SetSignalKernelSize(
39 std::atoi( args[ "mori_signal_kernel_size" ].c_str( ) )
41 mori->SetSignalThreshold(
42 std::atof( args[ "mori_signal_threshold" ].c_str( ) )
44 mori->SetSignalInfluence(
45 std::atof( args[ "mori_signal_influence" ].c_str( ) )
48 _TInputPixel( std::atof( args[ "mori_lower_threshold" ].c_str( ) ) ),
49 _TInputPixel( std::atof( args[ "mori_upper_threshold" ].c_str( ) ) ),
50 _TInputPixel( std::atof( args[ "mori_delta_threshold" ].c_str( ) ) )
52 double t = CTBronchi::MeasureTime( mori );
53 std::cout << "Mori executed in " << t << " s" << std::endl;
54 output = mori->GetOutput( );
56 std::map< std::string, std::string >::const_iterator i =
57 args.find( "out_mori" );
58 if( i != args.end( ) )
59 CTBronchi::WriteImage( output, i->second );
61 i = args.find( "out_signal" );
62 if( i != args.end( ) )
64 std::stringstream signal;
65 unsigned long nthr = mori->GetNumberOfEvaluatedThresholds( );
66 signal << "# nThr = " << nthr << std::endl;
67 signal << "# Opt = " << mori->GetOptimumThreshold( ) << std::endl;
68 for( unsigned long j = 0; j < nthr; ++j )
70 typename _TMori::TPeak p;
72 mori->GetSignalValues( j, x, y, p );
73 signal << x << " " << y << std::endl;
76 std::ofstream signals_str( i->second.c_str( ) );
77 signals_str << signal.str( );
81 output->DisconnectPipeline( );
82 return( mori->GetOptimumThreshold( ) );
87 #endif // __CTBronchi__Functions__h__