8 #include <itkImageFileReader.h>
9 #include <itkImageFileWriter.h>
11 #include <fpa/Image/MoriFilter.h>
13 // -------------------------------------------------------------------------
14 static const unsigned int Dim = 3;
16 typedef itk::Image< TPixel, Dim > TImage;
18 // -------------------------------------------------------------------------
19 std::string GetFullPath( const std::string& filename )
23 TCHAR full_path[MAX_PATH];
24 GetFullPathName(_T("foo.dat"), MAX_PATH, full_path, NULL);
27 char* buffer = realpath( filename.c_str( ), NULL );
28 std::string path = buffer;
33 // -------------------------------------------------------------------------
34 std::string GetFullPathToDirectory( const std::string& filename )
36 std::string path = GetFullPath( filename );
37 std::size_t found = path.find_last_of( "/\\" );
38 return( path.substr( 0, found + 1 ) );
41 // -------------------------------------------------------------------------
42 int main( int argc, char* argv[] )
44 // Command configuration
48 << "Usage: " << argv[ 0 ] << " input_image output_image"
53 std::string input_image_filename = GetFullPath( argv[ 1 ] );
54 std::string output_image_filename = argv[ 2 ];
56 // Try to guess initial seed
57 std::string seed_filename = GetFullPathToDirectory( argv[ 1 ] ) + "seed.txt";
58 std::ifstream seed_str( seed_filename.c_str( ) );
62 << "No \"seed.txt\" file in the same input image directory."
67 TImage::IndexType seed;
68 seed_str >> seed[ 0 ] >> seed[ 1 ] >> seed[ 2 ];
71 typedef itk::ImageFileReader< TImage > TReader;
72 TReader::Pointer reader = TReader::New( );
73 reader->SetFileName( input_image_filename );
76 typedef fpa::Image::MoriFilter< TImage, TImage > TFilter;
77 TFilter::Pointer filter = TFilter::New( );
78 filter->SetInput( reader->GetOutput( ) );
79 filter->SetSeed( seed );
80 filter->SetThresholdRange( -1024, 0 );
81 filter->SetInsideValue( 1 );
82 filter->SetOutsideValue( 0 );
85 typedef itk::ImageFileWriter< TImage > TWriter;
86 TWriter::Pointer writer = TWriter::New( );
87 writer->SetInput( filter->GetOutput( ) );
88 writer->SetFileName( output_image_filename );
95 catch( std::exception& err )
97 std::cerr << "Error caught: " << err.what( ) << std::endl;