]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/Mori.h
...
[FrontAlgorithms.git] / appli / CTBronchi / Mori.h
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__Mori__h__
6 #define __CTBronchi__Mori__h__
7
8 #include <map>
9 #include <CTBronchi/Functions.h>
10 #include <fpa/Filters/Image/Mori.h>
11
12 namespace CTBronchi
13 {
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
19     )
20   {
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;
26
27     _TOutputPixel i_val = _TOutputPixel( 1 );
28     _TOutputPixel o_val = _TOutputPixel( 0 );
29
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( ) ) )
37       );
38     mori->SetSignalKernelSize(
39       std::atoi( args[ "mori_signal_kernel_size" ].c_str( ) )
40       );
41     mori->SetSignalThreshold(
42       std::atof( args[ "mori_signal_threshold" ].c_str( ) )
43       );
44     mori->SetSignalInfluence(
45       std::atof( args[ "mori_signal_influence" ].c_str( ) )
46       );
47     mori->SetThresholds(
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( ) ) )
51       );
52     double t = CTBronchi::MeasureTime( mori );
53     std::cout << "Mori executed in " << t << " s" << std::endl;
54     output = mori->GetOutput( );
55
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 );
60
61     i = args.find( "out_signal" );
62     if( i != args.end( ) )
63     {
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 )
69       {
70         typename _TMori::TPeak p;
71         double x, y;
72         mori->GetSignalValues( j, x, y, p );
73         signal << x << " " << y << std::endl;
74
75       } // rof
76       std::ofstream signals_str( i->second.c_str( ) );
77       signals_str << signal.str( );
78       signals_str.close( );
79
80     } // fi
81     output->DisconnectPipeline( );
82     return( mori->GetOptimumThreshold( ) );
83   }
84
85 } // ecapseman
86
87 #endif // __CTBronchi__Functions__h__
88
89 // eof - $RCSfile$