Skip to content
Snippets Groups Projects
Commit c9feeed7 authored by Jordi Inglada's avatar Jordi Inglada
Browse files

Hu for images

parent b87ea8e9
No related branches found
No related tags found
No related merge requests found
......@@ -16,4 +16,6 @@ TARGET_LINK_LIBRARIES(ComplexMomentImageExample OTBCommon OTBIO ITKCommon ITKIO
ADD_EXECUTABLE(ComplexMomentPathExample ComplexMomentPathExample.cxx )
TARGET_LINK_LIBRARIES(ComplexMomentPathExample 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(HuMomentImageExample HuMomentImageExample.cxx )
TARGET_LINK_LIBRARIES(HuMomentImageExample 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 )
/*=========================================================================
Program : OTB (ORFEO ToolBox)
Authors : CNES - J. Inglada
Language : C++
Date : 13 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
// Software Guide : EndCommandLineArgs
// Software Guide : BeginLatex
//
// This example illustrates the use of the \doxygen{otb::HuMomentImageFunction}.
//
// The first step required to use this filter is to include its header file.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "otbHuImageFunction.h"
// Software Guide : EndCodeSnippet
int main(int argc, char ** argv )
{
if( argc != 3 )
{
std::cerr << "Usage: " << argv[0] << " inputImageFile ";
std::cerr << " moment_number" << std::endl;
return EXIT_FAILURE;
}
const char * inputFilename = argv[1];
unsigned int mNumber((unsigned char)::atoi(argv[2]));
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::HuImageFunction} is templated over the
// input image type and the output (real) type value, so we start by
// defining:
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef float MomentType;
typedef otb::HuImageFunction<InputImageType,
MomentType> HuType;
HuType::Pointer hmFunction =HuType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// We can choose the region and the pixel of the image which will
// used as coordinate origin
// for the moment computation
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
InputImageType::RegionType region;
InputImageType::SizeType size;
InputImageType::IndexType start;
start[0] = 0;
start[1] = 0;
size[0] = 50;
size[1] = 50;
reader->Update();
InputImageType::Pointer image = reader->GetOutput();
region.SetIndex( start );
region.SetSize( size );
image->SetRegions(region);
image->Update();
InputImageType::IndexType center;
center[0]=start[0]+size[0]/2;
center[1]=start[1]+size[1]/2;
// 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
hmFunction->SetInputImage( image );
hmFunction->SetNumber(mNumber);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// In order to get the value of the moment, we call the
// \code{EvaluateAtIndex} method.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
MomentType Result = hmFunction->EvaluateAtIndex(center);
std::cout << "The moment of order " << mNumber << " is equal to " << Result << std:: endl;
// Software Guide : EndCodeSnippet
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment