1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__Functions__h__
6 #define __CTBronchi__Functions__h__
11 #include <itkImageFileReader.h>
12 #include <itkImageFileWriter.h>
16 // -----------------------------------------------------------------------
17 double MeasureTime( itk::ProcessObject* f )
19 std::chrono::time_point< std::chrono::high_resolution_clock > s, e;
20 std::chrono::duration< double > t;
21 s = std::chrono::high_resolution_clock::now( );
23 e = std::chrono::high_resolution_clock::now( );
28 // -----------------------------------------------------------------------
29 template< class _TImagePtr >
30 void ReadImage( _TImagePtr& image, const std::string& fname )
32 typedef typename _TImagePtr::ObjectType _TImage;
33 typedef itk::ImageFileReader< _TImage > _TReader;
34 typename _TReader::Pointer reader = _TReader::New( );
35 reader->SetFileName( fname );
36 double t = MeasureTime( reader );
37 std::cout << "Read " << fname << " in " << t << " s" << std::endl;
38 image = reader->GetOutput( );
39 image->DisconnectPipeline( );
42 // -----------------------------------------------------------------------
43 template< class _TImagePtr >
44 void WriteImage( const _TImagePtr& image, const std::string& fname )
46 typedef typename _TImagePtr::ObjectType _TImage;
47 typedef itk::ImageFileWriter< _TImage > _TWriter;
48 typename _TWriter::Pointer writer = _TWriter::New( );
49 writer->SetFileName( fname );
50 writer->SetInput( image );
51 double t = MeasureTime( writer );
52 std::cout << "Wrote " << fname << " in " << t << " s" << std::endl;
55 // -----------------------------------------------------------------------
57 std::map< std::string, std::string >& args, int argc, char* argv[]
60 std::set< std::string > mandatory;
61 mandatory.insert( "in" );
62 mandatory.insert( "out" );
63 mandatory.insert( "seed" );
65 args[ "mori_minimum_threshold" ] = "-850";
66 args[ "mori_signal_kernel_size" ] = "20";
67 args[ "mori_signal_threshold" ] = "100";
68 args[ "mori_signal_influence" ] = "0.5";
69 args[ "mori_lower_threshold" ] = "-1024";
70 args[ "mori_upper_threshold" ] = "0";
71 args[ "mori_delta_threshold" ] = "1";
72 args[ "labelling_upper_threshold" ] = "-600";
73 args[ "random_walker_alpha" ] = "1";
74 args[ "random_walker_beta" ] = "100";
79 std::string cmd = argv[ i ] + 1;
82 std::stringstream seed;
84 << argv[ i + 1 ] << ";"
85 << argv[ i + 2 ] << ";"
87 args[ cmd ] = seed.str( );
92 args[ cmd ] = argv[ i + 1 ];
100 for( std::string t: mandatory )
101 complete &= ( args.find( t ) != args.end( ) );
106 << "Usage: " << argv[ 0 ] << std::endl
107 << "\t-in filename" << std::endl
108 << "\t-out filename" << std::endl
109 << "\t-seed x y z" << std::endl
110 << "\t[-out_mori filename]" << std::endl
111 << "\t[-out_signal filename]" << std::endl
112 << "\t[-out_labels filename]" << std::endl
113 << "\t[-out_diff filename]" << std::endl
114 << "\t[-mori_minimum_threshold value]" << std::endl
115 << "\t[-mori_signal_kernel_size value]" << std::endl
116 << "\t[-mori_signal_threshold value]" << std::endl
117 << "\t[-mori_signal_influence value]" << std::endl
118 << "\t[-mori_lower_threshold value]" << std::endl
119 << "\t[-mori_upper_threshold value]" << std::endl
120 << "\t[-mori_delta_threshold value]" << std::endl
121 << "\t[-labelling_upper_threshold value]" << std::endl
122 << "\t[-random_walker_alpha value]" << std::endl
123 << "\t[-random_walker_beta value]" << std::endl;
132 #endif // __CTBronchi__Functions__h__