diff --git a/Examples/FeatureExtraction/CMakeLists.txt b/Examples/FeatureExtraction/CMakeLists.txt index 61949f407803bbae9cc70c01eb9b86a4dfd4ebf3..281f8da5581f3d4061e0f2246720719479d9b867 100644 --- a/Examples/FeatureExtraction/CMakeLists.txt +++ b/Examples/FeatureExtraction/CMakeLists.txt @@ -10,4 +10,7 @@ TARGET_LINK_LIBRARIES(TouziEdgeDetectorExample OTBCommon OTBIO ITKCommon ITKIO I ADD_EXECUTABLE(HarrisExample HarrisExample.cxx ) TARGET_LINK_LIBRARIES(HarrisExample OTBCommon OTBIO ITKCommon ITKIO ITKNumerics ITKBasicFilters ITKCommon ITKStatistics itkvnl_inst itkvnl_algo itkvnl itkvcl itknetlib itksys ITKNrrdIO itkpng itktiff itkjpeg8 itkjpeg12 itkjpeg16 ITKMetaIO itkzlib ITKDICOMParser ITKEXPAT ) +ADD_EXECUTABLE(ComplexMomentImageExample ComplexMomentImageExample.cxx ) +TARGET_LINK_LIBRARIES(ComplexMomentImageExample OTBCommon OTBIO ITKCommon ITKIO ITKNumerics ITKBasicFilters ITKCommon ITKStatistics itkvnl_inst itkvnl_algo itkvnl itkvcl itknetlib itksys ITKNrrdIO itkpng itktiff itkjpeg8 itkjpeg12 itkjpeg16 ITKMetaIO itkzlib ITKDICOMParser ITKEXPAT ) + diff --git a/Examples/FeatureExtraction/ComplexMomentImageExample.cxx b/Examples/FeatureExtraction/ComplexMomentImageExample.cxx new file mode 100644 index 0000000000000000000000000000000000000000..10dee1a544937d4f3ae8d577130196dcf94fd1de --- /dev/null +++ b/Examples/FeatureExtraction/ComplexMomentImageExample.cxx @@ -0,0 +1,144 @@ +/*========================================================================= + + Program : OTB (ORFEO ToolBox) + Authors : CNES - J. Inglada + Language : C++ + Date : 7 April 2006 + Version : + Role : + $Id:$ + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "itkExceptionObject.h" +#include "itkImage.h" + +#include "otbImageFileReader.h" + + +// Software Guide : BeginCommandLineArgs +// INPUTS: {ROISpot5.png} +// 2 2 +// Software Guide : EndCommandLineArgs + +// Software Guide : BeginLatex +// +// This example illustrates the use of the \doxygen{otb::ComplexMomentImageFunction}. +// +// The first step required to use this filter is to include its header file. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbComplexMomentImageFunction.h" +// Software Guide : EndCodeSnippet + +int main(int argc, char ** argv ) +{ + if( argc != 4 ) + { + std::cerr << "Usage: " << argv[0] << " inputImageFile "; + std::cerr << " p q" << std::endl; + return EXIT_FAILURE; + } + + const char * inputFilename = argv[1]; + + unsigned int P((unsigned char)::atoi(argv[2])); + unsigned int Q((unsigned char)::atoi(argv[3])); + + + typedef unsigned char InputPixelType; + const unsigned int Dimension = 2; + + typedef itk::Image< InputPixelType, Dimension > InputImageType; + + typedef otb::ImageFileReader< InputImageType > ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + + reader->SetFileName(inputFilename); + + // Software Guide : BeginLatex + // + // The \doxygen{otb::ComplexMomentImageFunction} is templated over the + // input image type and the output complex type value, so we start by + // defining: + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef std::complex<float> ComplexType; + typedef otb::ComplexMomentImageFunction<InputImageType,ComplexType> CMType; + + CMType::Pointer cmFunction =CMType::New(); + + // Software Guide : EndCodeSnippet + + + + // Software Guide : BeginLatex + // + // Next, we plug the input image into the complex moment fucntion + // and we set its parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + reader->Update(); + cmFunction->SetInputImage( reader->GetOutput() ); + cmFunction->SetQ(Q); + cmFunction->SetP(P); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // We can chose the pixel of the image which will used as center + // for the moment computation + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + + InputImageType::IndexType center; + center[0]=50; + center[1]=50; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // We can also choose the size of the neighborhood around the + // center pixel for the moment computation. + // + // Software Guide : EndLatex + + + cmFunction->SetNeighborhoodRadius( 15 ); + + + + // Software Guide : BeginLatex + // In order to get the value of the moment, we call the + // \code{EvaluateAtIndex} method. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + ComplexType Result; + cmFunction->EvaluateAtIndex(center); + + std::cout << "The moment of order (" << P << "," << Q << ") is equal to " << Result << std:: endl; + + // Software Guide : EndCodeSnippet + + + + return EXIT_SUCCESS; +} +