Skip to content
Snippets Groups Projects
Commit d13db1bc authored by Patrick Imbo's avatar Patrick Imbo
Browse files

HuImage invariants

parent edb2b0ee
Branches
Tags
No related merge requests found
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkMeanImageFunction.h,v $
Language: C++
Date: $Date: 2003/09/10 14:29:15 $
Version: $Revision: 1.7 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _otbHuImageFunction_h
#define _otbHuImageFunction_h
#include "otbComplexMomentImageFunction.h"
#include <complex>
namespace otb
{
/**
* \class HuImageFunction
* \brief Calculate the Hu's invariant paramete.
*
* Calculate the Hu's invariant over an image defined as:
*
* \f$ \phi_{1} = c_{11} \f$
* \f$ \phi_{2} = c_{20} c\{02} \f$
*
* With :
*
* \f$ C_{p,q}=\int\int_{} (x+iy)^{p} \cdot (x-iy)^{q} \cdot f(x,y) \cdot
dx \cdot dy \f$
*
* And:
* + \f$(x,y)$f\ pixel localization;
* + \f$ f(x,y) $f\ the pixel value over the \f$(x,y)$f\ coordinate.
*
* This class is templated over the input image type and the
* coordinate representation type (e.g. float or double).
*
* \ingroup ImageFunctions
*/
template < class TInput,
class TOutput = std::complex<float >,
class TCoordRep = float >
class ITK_EXPORT HuImageFunction :
public ComplexMomentImageFunction< TInput, TOutput,TCoordRep >
{
public:
/** Standard class typedefs. */
typedef HuImageFunction Self;
typedef ComplexMomentImageFunction< TInput, TOutput,TCoordRep > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(HuImageFunction, ComplexMomentImageFunction);
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** InputImageType typedef support. */
typedef TInput InputType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
typedef typename Superclass::PointType PointType;
typedef TOutput ComplexType;
typedef ComplexMomentImageFunction<InputType,ComplexType> CMType;
/** Dimension of the underlying image. */
itkStaticConstMacro(ImageDimension, unsigned int,
InputType::ImageDimension);
/** Evalulate the function at specified index */
virtual ComplexType EvaluateAtIndex( const IndexType& index ) const;
/** Evaluate the function at non-integer positions */
virtual ComplexType Evaluate( const PointType& point ) const
{
IndexType index;
this->ConvertPointToNearestIndex( point, index );
return this->EvaluateAtIndex( index );
}
virtual ComplexType EvaluateAtContinuousIndex(
const ContinuousIndexType& cindex ) const
{
IndexType index;
this->ConvertContinuousIndexToNearestIndex( cindex, index );
return this->EvaluateAtIndex( index ) ;
}
/** Get/Set the radius of the neighborhood over which the
statistics are evaluated */
itkSetClampMacro(Number,short,1,7);
itkGetConstReferenceMacro( Number, short );
protected:
HuImageFunction();
~HuImageFunction(){};
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
HuImageFunction( const Self& ); //purposely not implemented
void operator=( const Self& ); //purposely not implemented
short m_Number;
};
} // namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbHuImageFunction.txx"
#endif
#endif
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkMeanImageFunction.txx,v $
Language: C++
Date: $Date: 2004/12/12 22:07:24 $
Version: $Revision: 1.12 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _otbHuImageFunction_txx
#define _otbHuImageFunction_txx
#include "otbHuImageFunction.h"
#include "itkImageRegionIterator.h"
#include "itkImage.h"
#include "itkConstNeighborhoodIterator.h"
#include <complex>
namespace otb
{
/**
* Constructor
*/
template < class TInput, class TOutput, class TCoordRep>
HuImageFunction<TInput,TOutput,TCoordRep>
::HuImageFunction()
{
m_Number =-1;
}
/**
*
*/
template < class TInput, class TOutput, class TCoordRep>
void
HuImageFunction<TInput,TOutput,TCoordRep>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
this->Superclass::PrintSelf(os,indent);
os << indent << " m_Number : " << m_Number << std::endl;
}
template < class TInput, class TOutput, class TCoordRep>
typename HuImageFunction<TInput,TOutput,TCoordRep>::ComplexType
HuImageFunction<TInput,TOutput,TCoordRep>
::EvaluateAtIndex(const IndexType& index) const
{
typename InputType::SizeType ImageSize;
ComplexType HuValue;
typename CMType::Pointer function =CMType::New();
if( !this->GetInputImage() )
{
return std::complex<float>(0.,0.); // A modifier
// return ( NumericTraits<RealType>::max() );
}
if ( !this->IsInsideBuffer( index ) )
{
return std::complex<float>(0.,0.); // A modifier
// return ( NumericTraits<RealType>::max() );
}
function->SetInputImage( this->GetInputImage() );
switch(m_Number)
{
case 1 :
{
ComplexType C11;
function->SetP(1);
function->SetQ(1);
C11 = function->EvaluateAtIndex( index );
HuValue = C11 ;
}
case 2:
{
ComplexType C20,C02;
function->SetP(2);
function->SetQ(0);
C20 = function->EvaluateAtIndex( index );
function->SetP(0);
function->SetQ(2);
C02 = function->EvaluateAtIndex( index );
HuValue = C20 * C02 ;
}
case 3:
{
ComplexType C30,C03;
function->SetP(3);
function->SetQ(0);
C30 = function->EvaluateAtIndex( index );
function->SetP(0);
function->SetQ(3);
C03 = function->EvaluateAtIndex( index );
HuValue = C30 * C03 ;
}
case 4:
{
ComplexType C21,C12;
function->SetP(2);
function->SetQ(1);
C21 = function->EvaluateAtIndex( index );
function->SetP(1);
function->SetQ(2);
C12 = function->EvaluateAtIndex( index );
HuValue = C21 * C12 ;
}
}
return (static_cast<ComplexType>(HuValue) );
}
} // namespace otb
#endif
......@@ -73,6 +73,10 @@ ADD_TEST(feTuTestFLST ${FEATUREEXTRACTION_TESTS}
ADD_TEST(feTuComplexMomentImage ${FEATUREEXTRACTION_TESTS}
otbComplexMomentImage
${INPUTDATA}/TeteAToto.png 1 1)
ADD_TEST(feTuHuImage ${FEATUREEXTRACTION_TESTS}
otbHuImage
${INPUTDATA}/TeteAToto.png)
ADD_TEST(feTuTouzi ${FEATUREEXTRACTION_TESTS}
otbTouziEdgeDetector
......@@ -106,6 +110,7 @@ otbDrawPathList.cxx
otbDrawPath.cxx
otbDrawPathAlign.cxx
otbComplexMomentImage.cxx
otbHuImage.cxx
otbTouziEdgeDetector.cxx
otbTupinEdgeDetector.cxx
)
......
......@@ -18,6 +18,7 @@ REGISTER_TEST(otbDrawPathListTracerLignes);
REGISTER_TEST(otbDrawPathDessinCarre);
REGISTER_TEST(otbDrawPathAlign);
REGISTER_TEST(otbComplexMomentImage);
REGISTER_TEST(otbHuImage);
REGISTER_TEST(otbTouziEdgeDetector);
REGISTER_TEST(otbTupinEdgeDetector);
}
/*=========================================================================
Programme : OTB (ORFEO ToolBox)
Auteurs : CS - P.Imbo
Language : C++
Date : 10 mars 2006
Version :
Role :
$Id$
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkExceptionObject.h"
#include "itkImage.h"
#include "otbImageFileReader.h"
#include "otbHuImageFunction.h"
int otbHuImage( int argc, char ** argv )
{
try
{
const char * inputFilename = argv[1];
unsigned int Number = 1;
typedef unsigned char InputPixelType;
const unsigned int Dimension = 2;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
typedef otb::ImageFileReader< InputImageType > ReaderType;
typedef std::complex<float> ComplexType;
typedef otb::HuImageFunction<InputImageType,ComplexType> FunctionType;
InputImageType::RegionType region;
InputImageType::SizeType size;
InputImageType::IndexType start;
start.Fill( 0 );
size[0] = 50;
size[1] = 50;
ReaderType::Pointer reader = ReaderType::New();
FunctionType::Pointer function =FunctionType::New();
reader->SetFileName( inputFilename );
InputImageType::Pointer image = reader->GetOutput();
region.SetIndex( start );
region.SetSize( size );
image->SetRegions(region);
image->Update();
function->SetInputImage( image );
function->SetQ(Number);
InputImageType::IndexType index;
index[0]=10;
index[1]=10;
ComplexType Result;
Result = function->EvaluateAtIndex( index );
std::cout << "Hu("<<Number<<") = "<< Result <<std::endl;
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Exception levee inconnue !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment