IF(BUILD_EXAMPLES)
SET(
APPLIS
+ example
+ example_BinaryDistanceMap
example_ImageAlgorithmRegionGrow_00
example_ImageAlgorithmDijkstra_00
example_ImageAlgorithmFastMarching_00
--- /dev/null
+#include <ctime>
+#include <iostream>
+#include <string>
+
+#include <itkImage.h>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+#include <itkInvertIntensityImageFilter.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkDanielssonDistanceMapImageFilter.h>
+
+/*
+#include <cmath>
+#include <deque>
+#include <limits>
+#include <map>
+
+#include <itkConstNeighborhoodIterator.h>
+#include <itkNeighborhoodIterator.h>
+#include <itkImageToVTKImageFilter.h>
+
+
+#include <vtkPoints.h>
+#include <vtkCellArray.h>
+#include <vtkFloatArray.h>
+#include <vtkPolyData.h>
+#include <vtkSmartPointer.h>
+
+#include <fpa/Image/DijkstraWithSphereBacktracking.h>
+#include <fpa/VTK/ImageMPR.h>
+#include <fpa/VTK/Image3DObserver.h>
+*/
+
+// -------------------------------------------------------------------------
+const unsigned int Dim = 3;
+typedef unsigned char TPixel;
+typedef float TScalar;
+typedef itk::Image< TPixel, Dim > TImage;
+typedef itk::Image< TScalar, Dim > TScalarImage;
+typedef itk::ImageFileReader< TImage > TImageReader;
+typedef itk::ImageFileWriter< TScalarImage > TImageWriter;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+ if( argc < 3 )
+ {
+ std::cerr
+ << "Usage: " << argv[ 0 ]
+ << " input_image output_image"
+ << std::endl;
+ return( 1 );
+
+ } // fi
+ std::string input_image_fn = argv[ 1 ];
+ std::string output_image_fn = argv[ 2 ];
+
+ // Read image
+ TImageReader::Pointer input_image_reader = TImageReader::New( );
+ input_image_reader->SetFileName( input_image_fn );
+ try
+ {
+ input_image_reader->Update( );
+ }
+ catch( itk::ExceptionObject& err )
+ {
+ std::cerr << "Error caught: " << err << std::endl;
+ return( 1 );
+
+ } // yrt
+
+ // Invert intensity
+ typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax;
+ TMinMax::Pointer minmax = TMinMax::New( );
+ minmax->SetImage( input_image_reader->GetOutput( ) );
+ minmax->Compute( );
+
+ typedef itk::InvertIntensityImageFilter< TImage > TInvert;
+ TInvert::Pointer invert = TInvert::New( );
+ invert->SetInput( input_image_reader->GetOutput( ) );
+ invert->SetMaximum( minmax->GetMaximum( ) );
+
+ typedef itk::DanielssonDistanceMapImageFilter< TImage, TScalarImage > TDistance;
+ TDistance::Pointer distance = TDistance::New( );
+ distance->SetInput( invert->GetOutput( ) );
+ distance->InputIsBinaryOn( );
+ distance->SquaredDistanceOn( );
+ std::clock_t start = std::clock( );
+ distance->Update( );
+ std::clock_t end = std::clock( );
+ double seconds = double( end - start ) / double( CLOCKS_PER_SEC );
+ std::cout << "Distance map time = " << seconds << std::endl;
+
+ TImageWriter::Pointer writer = TImageWriter::New( );
+ writer->SetInput( distance->GetOutput( ) );
+ writer->SetFileName( output_image_fn );
+ writer->Update( );
+
+ return( 0 );
+}
+
+// eof - $RCSfile$
#include <itkImageFileWriter.h>
#include <itkImageToVTKImageFilter.h>
+#include <itkMinimumMaximumImageCalculator.h>
+#include <itkInvertIntensityImageFilter.h>
+
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
// -------------------------------------------------------------------------
const unsigned int Dim = 3;
-typedef double TPixel;
-typedef double TScalar;
+typedef float TPixel;
+typedef float TScalar;
typedef itk::Image< TPixel, Dim > TImage;
typedef itk::ImageToVTKImageFilter< TImage > TVTKImage;
typedef itk::ImageFileReader< TImage > TImageReader;
-typedef itk::ImageFileWriter< TImage > TImageWriter;
+typedef itk::ImageFileWriter< TImage > TImageWriter;
typedef fpa::Image::DijkstraWithSphereBacktracking< TImage, TScalar > TDijkstra;
typedef fpa::VTK::ImageMPR TMPR;
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
- if( argc < 4 )
+ if( argc < 6 )
{
std::cerr
<< "Usage: " << argv[ 0 ]
- << " input_image output_image"
- << " neighborhood_order"
+ << " input_image x y z output_image"
<< " visual_debug"
<< std::endl;
return( 1 );
} // fi
std::string input_image_fn = argv[ 1 ];
- std::string output_image_fn = argv[ 2 ];
- unsigned int neighborhood_order = std::atoi( argv[ 3 ] );
+ TImage::PointType seed_pnt;
+ seed_pnt[ 0 ] = std::atof( argv[ 2 ] );
+ seed_pnt[ 1 ] = std::atof( argv[ 3 ] );
+ seed_pnt[ 2 ] = std::atof( argv[ 4 ] );
+ std::string output_image_fn = argv[ 5 ];
bool visual_debug = false;
- if( argc > 4 )
- visual_debug = ( std::atoi( argv[ 4 ] ) == 1 );
+ if( argc > 6 )
+ visual_debug = ( std::atoi( argv[ 6 ] ) == 1 );
// Read image
TImageReader::Pointer input_image_reader = TImageReader::New( );
view.SetSize( 800, 800 );
view.SetImage( vtk_image->GetOutput( ) );
- // Wait for a seed to be given
- while( view.GetNumberOfSeeds( ) == 0 )
- view.Start( );
+ // Allow some interaction
+ 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 );
+ std::cout << seed_idx << " " << seed_pnt << std::endl;
+ seed_idx[ 0 ] = 256;
+ seed_idx[ 1 ] = 313;
+ seed_idx[ 2 ] = 381;
// Extract paths
TDijkstra::Pointer paths = TDijkstra::New( );
paths->AddSeed( seed_idx, TScalar( 0 ) );
paths->SetInput( input_image );
- paths->SetNeighborhoodOrder( neighborhood_order );
+ paths->SetNeighborhoodOrder( 2 );
if( visual_debug )
{