// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #include #include #include #include #include #include #include // ------------------------------------------------------------------------- const unsigned int Dim = 3; typedef short TInputPixel; typedef unsigned char TLabelPixel; typedef itk::Image< TInputPixel, Dim > TImage; typedef itk::Image< TLabelPixel, Dim > TLabelImage; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { std::map< std::string, std::string > args; try { if( CTBronchi::ParseArgs( args, argc, argv ) ) { // Parse seed TImage::PointType seed; char* str = new char[ args[ "seed" ].size( ) + 1 ]; strcpy( str, args[ "seed" ].c_str( ) ); seed[ 0 ] = std::atof( strtok( str, ";" ) ); seed[ 1 ] = std::atof( strtok( NULL, ";" ) ); seed[ 2 ] = std::atof( strtok( NULL, ";" ) ); // Read input image TImage::Pointer input_image; CTBronchi::ReadImage( input_image, args[ "in" ] ); // Mori segmentation TLabelImage::Pointer mori; TInputPixel opt_thr = CTBronchi::Mori( mori, input_image, seed, args ); // Label image TLabelImage::Pointer labels; CTBronchi::Label( labels, input_image, mori, opt_thr, args ); // Final labels TLabelImage::Pointer final_labels; CTBronchi::RandomWalker( final_labels, input_image, labels, args ); // Extract label 1 typedef itk::BinaryThresholdImageFilter< TLabelImage, TLabelImage > TBinThr; TBinThr::Pointer bin_thr = TBinThr::New( ); bin_thr->SetInput( final_labels ); bin_thr->SetLowerThreshold( 1 ); bin_thr->SetUpperThreshold( 1 ); bin_thr->SetInsideValue( 1 ); bin_thr->SetOutsideValue( 0 ); double t = CTBronchi::MeasureTime( bin_thr ); std::cout << "Label extracted in " << t << " s" << std::endl; TLabelImage::Pointer segmentation = bin_thr->GetOutput( ); // Save CTBronchi::WriteImage( segmentation, args[ "out" ] ); // Save difference std::map< std::string, std::string >::const_iterator i = args.find( "out_diff" ); if( i != args.end( ) ) { typedef itk::AbsoluteValueDifferenceImageFilter< TLabelImage, TLabelImage, TLabelImage > TDiff; TDiff::Pointer diff = TDiff::New( ); diff->SetInput1( mori ); diff->SetInput2( segmentation ); t = CTBronchi::MeasureTime( diff ); std::cout << "Difference computed in " << t << " s" << std::endl; TLabelImage::Pointer difference = diff->GetOutput( ); CTBronchi::WriteImage( difference, i->second ); } // fi } else return( 1 ); } catch( std::exception& err ) { std::cerr << "===============================" << std::endl << "Error caught: " << std::endl << err.what( ) << "===============================" << std::endl << std::endl; return( 1 ); } // yrt return( 0 ); } // eof - $RCSfile$