]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/Mori.h
a228fa54d059870dfc357dd7664b2f0f80381a02
[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 >
16   void Mori(
17     _TOutputPtr& output, const _TInputPtr& input,
18     const 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
26     typename _TMori::Pointer mori = _TMori::New( );
27     mori->SetInput( input );
28     mori->SetSeed( global_seed );
29     mori->SetInsideValue( inside_value );
30     mori->SetOutsideValue( outside_value );
31     mori->SetMinimumThreshold(
32       _TInputPixel( std::atof( args[ "mori_minimum_threshold" ].c_str( ) ) )
33       );
34     mori->SetSignalKernelSize(
35       std::atoi( args[ "mori_signal_kernel_size" ].c_str( ) )
36       );
37     mori->SetSignalThreshold(
38       std::atof( args[ "mori_signal_threshold" ].c_str( ) )
39       );
40     mori->SetSignalInfluence(
41       std::atof( args[ "mori_signal_influence" ].c_str( ) )
42       );
43     mori->SetThresholds(
44       _TInputPixel( std::atof( args[ "mori_lower_threshold" ].c_str( ) ) ),
45       _TInputPixel( std::atof( args[ "mori_upper_threshold" ].c_str( ) ) ),
46       _TInputPixel( std::atof( args[ "mori_delta_threshold" ].c_str( ) ) )
47       );
48     double t = CTBronchi::MeasureTime( mori );
49     std::cout << "Mori executed in " << t << " s" << std::endl;
50     output = mori->GetOutput( );
51
52     std::map< std::string, std::string >::const_iterator i =
53       args.find( "out_mori" );
54     if( i != args.end( ) )
55       CTBronchi::WriteImage( output, i->second );
56
57     i = args.find( "out_signal" );
58     if( i != args.end( ) )
59     {
60       std::stringstream signal;
61       unsigned long nthr = mori->GetNumberOfEvaluatedThresholds( );
62       signal << "# nThr = " << nthr << std::endl;
63       signal << "# Opt  = " << mori->GetOptimumThreshold( ) << std::endl;
64       for( unsigned long j = 0; j < nthr; ++j )
65       {
66         typename _TMori::TPeak p;
67         double x, y;
68         mori->GetSignalValues( j, x, y, p );
69         signal << x << " " << y << std::endl;
70
71       } // rof
72
73       std::ofstream signals_str( i->second.c_str( ) );
74       signals_str << signal.str( );
75       signals_str.close( );
76
77     } // fi
78     output->DisconnectPipeline( );
79   }
80
81 } // ecapseman
82
83 #endif // __CTBronchi__Functions__h__
84
85 // eof - $RCSfile$