// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __CTBronchi__Functions__h__ #define __CTBronchi__Functions__h__ #include #include #include #include #include namespace CTBronchi { // ----------------------------------------------------------------------- double MeasureTime( itk::ProcessObject* f ) { std::chrono::time_point< std::chrono::high_resolution_clock > s, e; std::chrono::duration< double > t; s = std::chrono::high_resolution_clock::now( ); f->Update( ); e = std::chrono::high_resolution_clock::now( ); t = e - s; return( t.count( ) ); } // ----------------------------------------------------------------------- template< class _TImagePtr > void ReadImage( _TImagePtr& image, const std::string& fname ) { typedef typename _TImagePtr::ObjectType _TImage; typedef itk::ImageFileReader< _TImage > _TReader; typename _TReader::Pointer reader = _TReader::New( ); reader->SetFileName( fname ); double t = MeasureTime( reader ); std::cout << "Read " << fname << " in " << t << " s" << std::endl; image = reader->GetOutput( ); image->DisconnectPipeline( ); } // ----------------------------------------------------------------------- template< class _TImagePtr > void WriteImage( const _TImagePtr& image, const std::string& fname ) { typedef typename _TImagePtr::ObjectType _TImage; typedef itk::ImageFileWriter< _TImage > _TWriter; typename _TWriter::Pointer writer = _TWriter::New( ); writer->SetFileName( fname ); writer->SetInput( image ); double t = MeasureTime( writer ); std::cout << "Wrote " << fname << " in " << t << " s" << std::endl; } // ----------------------------------------------------------------------- bool ParseArgs( std::map< std::string, std::string >& args, int argc, char* argv[] ) { std::set< std::string > mandatory; mandatory.insert( "in" ); mandatory.insert( "out" ); mandatory.insert( "seed" ); args[ "mori_minimum_threshold" ] = "-850"; args[ "mori_signal_kernel_size" ] = "20"; args[ "mori_signal_threshold" ] = "100"; args[ "mori_signal_influence" ] = "0.5"; args[ "mori_lower_threshold" ] = "-1024"; args[ "mori_upper_threshold" ] = "0"; args[ "mori_delta_threshold" ] = "1"; args[ "labelling_upper_threshold" ] = "-600"; args[ "random_walker_alpha" ] = "1"; args[ "random_walker_beta" ] = "100"; int i = 1; while( i < argc ) { std::string cmd = argv[ i ] + 1; if( cmd == "seed" ) { std::stringstream seed; seed << argv[ i + 1 ] << ";" << argv[ i + 2 ] << ";" << argv[ i + 3 ]; args[ cmd ] = seed.str( ); i += 4; } else { args[ cmd ] = argv[ i + 1 ]; i += 2; } // fi } // elihw bool complete = true; for( std::string t: mandatory ) complete &= ( args.find( t ) != args.end( ) ); if( !complete ) { std::cerr << "Usage: " << argv[ 0 ] << std::endl << "\t-in filename" << std::endl << "\t-out filename" << std::endl << "\t-seed x y z" << std::endl << "\t[-out_mori filename]" << std::endl << "\t[-out_signal filename]" << std::endl << "\t[-out_labels filename]" << std::endl << "\t[-out_diff filename]" << std::endl << "\t[-mori_minimum_threshold value]" << std::endl << "\t[-mori_signal_kernel_size value]" << std::endl << "\t[-mori_signal_threshold value]" << std::endl << "\t[-mori_signal_influence value]" << std::endl << "\t[-mori_lower_threshold value]" << std::endl << "\t[-mori_upper_threshold value]" << std::endl << "\t[-mori_delta_threshold value]" << std::endl << "\t[-labelling_upper_threshold value]" << std::endl << "\t[-random_walker_alpha value]" << std::endl << "\t[-random_walker_beta value]" << std::endl; return( false ); } // fi return( true ); } } // ecapseman #endif // __CTBronchi__Functions__h__ // eof - $RCSfile$