From: Leonardo Florez-Valencia Date: Fri, 13 Mar 2015 11:39:43 +0000 (-0500) Subject: Second order neighbors debugged in 3D X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=37d7623729a0100a6517f8bfe4e3417db8367697;p=FrontAlgorithms.git Second order neighbors debugged in 3D --- diff --git a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx index b78929b..c07dc8e 100644 --- a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx +++ b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx @@ -41,25 +41,23 @@ typedef fpa::VTK::Image3DObserver< TDijkstra, vtkRenderWindow > TDijkstraObs; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 6 ) + if( argc < 4 ) { std::cerr << "Usage: " << argv[ 0 ] - << " input_image x y z output_image" + << " input_image output_image" + << " neighborhood_order" << " visual_debug" << std::endl; return( 1 ); } // fi std::string input_image_fn = argv[ 1 ]; - TImage::IndexType seed_idx; - seed_idx[ 0 ] = std::atoi( argv[ 2 ] ); - seed_idx[ 1 ] = std::atoi( argv[ 3 ] ); - seed_idx[ 2 ] = std::atoi( argv[ 4 ] ); - std::string output_image_fn = argv[ 5 ]; + std::string output_image_fn = argv[ 2 ]; + unsigned int neighborhood_order = std::atoi( argv[ 3 ] ); bool visual_debug = false; - if( argc > 6 ) - visual_debug = ( std::atoi( argv[ 6 ] ) == 1 ); + if( argc > 4 ) + visual_debug = ( std::atoi( argv[ 4 ] ) == 1 ); // Read image TImageReader::Pointer input_image_reader = TImageReader::New( ); @@ -86,14 +84,25 @@ int main( int argc, char* argv[] ) view.SetSize( 800, 800 ); view.SetImage( vtk_image->GetOutput( ) ); - // Allow some interaction - view.Start( ); + // Wait for a seed to be given + while( view.GetNumberOfSeeds( ) == 0 ) + view.Start( ); + + // Get seed from user + double seed[ 3 ]; + view.GetSeed( 0, seed ); + TImage::PointType seed_pnt; + seed_pnt[ 0 ] = seed[ 0 ]; + seed_pnt[ 1 ] = seed[ 1 ]; + seed_pnt[ 2 ] = seed[ 2 ]; + TImage::IndexType seed_idx; + input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx ); // Extract paths TDijkstra::Pointer paths = TDijkstra::New( ); paths->AddSeed( seed_idx, TScalar( 0 ) ); paths->SetInput( input_image ); - paths->SetNeighborhoodOrder( 1 ); + paths->SetNeighborhoodOrder( neighborhood_order ); if( visual_debug ) { diff --git a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx index 06ff805..109d1d1 100644 --- a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx +++ b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx @@ -134,6 +134,7 @@ int main( int argc, char* argv[] ) distanceMap->SetInput( segmentor->GetOutput( ) ); distanceMap->InputIsBinaryOn( ); distanceMap->SquaredDistanceOn( ); + distanceMap->UseImageSpacingOn( ); start = std::clock( ); distanceMap->Update( ); end = std::clock( ); @@ -156,7 +157,7 @@ int main( int argc, char* argv[] ) TDijkstra::Pointer paths = TDijkstra::New( ); paths->AddSeed( segmentor->GetSeed( 0 ), TScalar( 0 ) ); paths->SetInput( distanceMap->GetOutput( ) ); - paths->SetNeighborhoodOrder( 1 ); + paths->SetNeighborhoodOrder( 2 ); if( visual_debug ) { diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index 7800a54..1b7eab9 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -79,9 +79,9 @@ _Edge( const TVertex& a, const TVertex& b ) const for( unsigned int d = 0; d < I::ImageDimension; d++ ) dist += std::abs( long( a[ d ] ) - long( b[ d ] ) ); if( this->m_NeighborhoodOrder == 1 ) - return( dist == 0 || dist == 1 ); + return( dist <= 1 ); else - return( dist == 0 || dist == 1 || dist == 2 ); + return( dist <= I::ImageDimension ); } // -------------------------------------------------------------------------