From: Leonardo Flórez-Valencia Date: Sat, 25 Mar 2017 01:25:46 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=FrontAlgorithms.git;a=commitdiff_plain;h=14bfa97aef83c54e1cf3813594bd9ae03f23f7f5 ... --- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 297746a..2bed4e5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -10,6 +10,10 @@ IF(BUILD_EXAMPLES) #BronchiiInitialSegmentationWithMori #BronchiiInitialSegmentationWithBinaryThresholdRegionGrow ) + OPTION(BUILD_EXAMPLE_SANDBOX "Build sandbox example." OFF) + IF(BUILD_EXAMPLE_SANDBOX) + LIST(APPEND _examples sandbox) + ENDIF(BUILD_EXAMPLE_SANDBOX) INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/libs ${PROJECT_BINARY_DIR}/libs diff --git a/examples/sandbox.cxx b/examples/sandbox.cxx new file mode 100644 index 0000000..d27bea9 --- /dev/null +++ b/examples/sandbox.cxx @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +static const unsigned int VDim = 2; +typedef short TPixel; +typedef double TScalar; +typedef itk::Image< TPixel, VDim > TImage; +typedef itk::Image< TScalar, VDim > TScalarImage; +typedef itk::ImageFileReader< TImage > TReader; +typedef itk::ImageFileWriter< TScalarImage > TWriter; +typedef fpa::Image::Dijkstra< TImage, TScalarImage > TFilter; +typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax; +typedef itk::ImageRegionConstIteratorWithIndex< TImage > TIterator; + +typedef fpa::Image::Functors::GaussianWeight< TImage, TScalar > TVertexFunc; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + // Get arguments + if( argc < 5 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_image input_seeds output_image beta" + << std::endl; + return( 1 ); + + } // fi + std::string input_image_filename = argv[ 1 ]; + std::string input_seeds_filename = argv[ 2 ]; + std::string output_image_filename = argv[ 3 ]; + double beta = std::atof( argv[ 4 ] ); + + // Read seeds + TReader::Pointer input_seeds = TReader::New( ); + input_seeds->SetFileName( input_seeds_filename ); + try + { + input_seeds->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + TMinMax::Pointer minmax = TMinMax::New( ); + minmax->SetImage( input_seeds->GetOutput( ) ); + minmax->Compute( ); + + // Read image + TReader::Pointer input_image = TReader::New( ); + input_image->SetFileName( input_image_filename ); + + // Prepare dijkstra filter + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input_image->GetOutput( ) ); + filter->StopAtOneFrontOff( ); + + // Assign seeds + /* TODO + TIterator sIt( + input_seeds->GetOutput( ), + input_seeds->GetOutput( )->GetRequestedRegion( ) + ); + for( sIt.GoToBegin( ); !sIt.IsAtEnd( ); ++sIt ) + if( sIt.Get( ) > minmax->GetMinimum( ) ) + filter->AddSeed( sIt.GetIndex( ) ); + */ + TImage::IndexType seed; + /* TODO + seed[ 0 ] = 248; + seed[ 1 ] = 326; + seed[ 2 ] = 312; + */ + seed[ 0 ] = 482; + seed[ 1 ] = 57; + filter->AddSeed( seed ); + + seed[ 0 ] = 306; + seed[ 1 ] = 439; + filter->AddSeed( seed ); + + TVertexFunc::Pointer vertex_func = TVertexFunc::New( ); + vertex_func->SetBeta( beta ); + filter->SetFunctor( vertex_func ); + + TWriter::Pointer writer = TWriter::New( ); + writer->SetInput( filter->GetOutput( ) ); + writer->SetFileName( output_image_filename ); + + try + { + writer->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "ERROR: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/libs/fpa/Image/Dijkstra.h b/libs/fpa/Image/Dijkstra.h index 8516d7b..1df0836 100644 --- a/libs/fpa/Image/Dijkstra.h +++ b/libs/fpa/Image/Dijkstra.h @@ -65,7 +65,6 @@ namespace fpa virtual void GenerateData( ) override { // Configure functors with input image - typedef typename TFilter::TInputImage _TInputIage; typedef typename TFilter::TOutputValue _TOutputValue; typedef fpa::Image::Functors::VertexParentBase< _TInputImage, _TOutputValue > _TVFunc; _TVFunc* vfunc = diff --git a/libs/fpa/Image/Functors/GaussianWeight.h b/libs/fpa/Image/Functors/GaussianWeight.h new file mode 100644 index 0000000..3b2212a --- /dev/null +++ b/libs/fpa/Image/Functors/GaussianWeight.h @@ -0,0 +1,78 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#ifndef __fpa__Image__Functors__GaussianWeight__h__ +#define __fpa__Image__Functors__GaussianWeight__h__ + +#include +#include + +namespace fpa +{ + namespace Image + { + namespace Functors + { + /** + */ + template< class _TInputImage, class _TOutputValue > + class GaussianWeight + : public fpa::Image::Functors::VertexParentBase< _TInputImage, _TOutputValue > + { + public: + typedef _TInputImage TInputImage; + typedef _TOutputValue TOutputValue; + typedef GaussianWeight Self; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + typedef fpa::Image::Functors::VertexParentBase< TInputImage, TOutputValue > Superclass; + + typedef typename Superclass::TVertex TVertex; + + public: + itkNewMacro( Self ); + itkTypeMacro( + fpa::Image::Functors::GaussianWeight, + fpa::Image::Functors::VertexParentBase + ); + + itkGetConstMacro( Beta, double ); + itkSetMacro( Beta, double ); + + public: + virtual TOutputValue Evaluate( + const TVertex& a, const TVertex& p + ) const override + { + double va = double( this->m_Image->GetPixel( a ) ); + double vp = double( this->m_Image->GetPixel( p ) ); + double d = va - vp; + return( TOutputValue( std::exp( -d * d * this->m_Beta ) ) ); + } + + protected: + GaussianWeight( ) + : Superclass( ), + m_Beta( double( 1 ) ) + { } + virtual ~GaussianWeight( ) { } + + private: + GaussianWeight( const Self& other ); + Self& operator=( const Self& other ); + + protected: + double m_Beta; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#endif // __fpa__Image__Functors__GaussianWeight__h__ + +// eof - $RCSfile$