]> Creatis software - FrontAlgorithms.git/commitdiff
Second order neighbors debugged in 3D
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Mar 2015 11:39:43 +0000 (06:39 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Mar 2015 11:39:43 +0000 (06:39 -0500)
appli/examples/example_ImageAlgorithmDijkstra_03.cxx
appli/examples/example_ImageAlgorithm_Skeletonization.cxx
lib/fpa/Image/Algorithm.hxx

index b78929b5685ba0c6d85e214751ee745700c9c9c6..c07dc8ef3d23b5303bee7c4c5bc261f558086f6e 100644 (file)
@@ -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 )
   {
index 06ff8057bd5b7d3c37a39a56a4e424dc943f2788..109d1d1956ddffe062b9107082ed27681ccf245d 100644 (file)
@@ -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 )
   {
index 7800a549576e7f378b1454ed39013d5996c72cff..1b7eab945b71940b7c9e8cbff464faef7b44300a 100644 (file)
@@ -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 );
 }
 
 // -------------------------------------------------------------------------