From 70a0687f2e04f50e62eaf15fe8439d44e3a72a34 Mon Sep 17 00:00:00 2001 From: Patrick Imbo <patrick.imbo@c-s.fr> Date: Wed, 22 Mar 2006 14:01:07 +0000 Subject: [PATCH] Moments complexe avec Path --- Code/Common/otbPathFunction.h | 214 ++++++++++++++++++ Code/Common/otbPathFunction.txx | 88 +++++++ .../otbComplexMomentPathFunction.h | 109 +++++++++ .../otbComplexMomentPathFunction.txx | 140 ++++++++++++ .../otbGeometricMomentImageFunction.h | 5 +- .../otbGeometricMomentPathFunction.h | 73 ++++++ .../otbRealMomentPathFunction.h | 74 ++++++ Testing/Code/BasicFilters/CMakeLists.txt | 17 +- Testing/Code/BasicFilters/otbFrostFilter.cxx | 115 +++++++++- .../otbComplexMomentPath.cxx | 6 +- 10 files changed, 821 insertions(+), 20 deletions(-) create mode 100644 Code/Common/otbPathFunction.h create mode 100644 Code/Common/otbPathFunction.txx create mode 100644 Code/FeatureExtraction/otbComplexMomentPathFunction.h create mode 100644 Code/FeatureExtraction/otbComplexMomentPathFunction.txx create mode 100644 Code/FeatureExtraction/otbGeometricMomentPathFunction.h create mode 100644 Code/FeatureExtraction/otbRealMomentPathFunction.h diff --git a/Code/Common/otbPathFunction.h b/Code/Common/otbPathFunction.h new file mode 100644 index 0000000000..e1ba7e111c --- /dev/null +++ b/Code/Common/otbPathFunction.h @@ -0,0 +1,214 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Evaluate a function of an image over a specific path + $Id:$ + +=========================================================================*/ +#ifndef _otbPathFunction_h +#define _otbPathFunction_h + +#include "itkFunctionBase.h" +#include "itkPoint.h" +#include "itkIndex.h" +#include "itkContinuousIndex.h" +#include "itkImageBase.h" + +namespace otb +{ + + +/** \class PathFunction + * \brief Evaluates a function of an image over a specific path. + * + * PathFunction is a baseclass for all objects that evaluates + * a function of an image using a path list. + * This class is templated over the input image type, the path type + * and the function output and the coordinate representation type + * (e.g. float or double). + * + * The input image is set via method SetInputImage(). + * The input path is set via method SetInputPath(). + * + * + * \sa Path + * + * \ingroup PathFunction + */ +template < +class TInputImage, +class TInputPath, +class TOutput, +class TCoordRep = float +> +class ITK_EXPORT PathFunction : + public FunctionBase< Point<TCoordRep, + ::itk::GetImageDimension<TInputImage>::ImageDimension>, + TOutput > +{ +public: + /** Dimension underlying input image. */ + itkStaticConstMacro(ImageDimension, unsigned int, + TInputImage::ImageDimension); + + /** Standard class typedefs. */ + typedef PathFunction Self; + typedef itk::FunctionBase< Point<TCoordRep, + itkGetStaticConstMacro(ImageDimension)>, + TOutput > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(PathFunction, itk::FunctionBase); + + /** InputImageType typedef support. */ + typedef TInputImage InputImageType; + + /** InputPixel typedef support */ + typedef typename InputImageType::PixelType InputPixelType; + + /** InputImagePointer typedef support */ + typedef typename InputImageType::ConstPointer InputImageConstPointer; + + + /** InputPathType typedef support. */ + typedef TInputPath InputPathType; + + /** InputPathPointer typedef support */ + typedef typename InputPathType::ConstPointer InputPathConstPointer; + + + + /** OutputType typedef support. */ + typedef TOutput OutputType; + + /** CoordRepType typedef support. */ + typedef TCoordRep CoordRepType; + + /** Index Type. */ + typedef typename InputImageType::IndexType IndexType; + + /** ContinuousIndex Type. */ + typedef ContinuousIndex<TCoordRep,itkGetStaticConstMacro(ImageDimension)> + ContinuousIndexType; + + /** Point Type. */ + typedef Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType; + + /** Set the input image. + * \warning this method caches BufferedRegion information. + * If the BufferedRegion has changed, user must call + * SetInputImage again to update cached values. */ + virtual void SetInputImage( const InputImageType * ptr ); + + /** Get the input image. */ + const InputImageType * GetInputImage() const + { return m_Image.GetPointer(); } + + /** Set the input path. */ + virtual void SetInputPath( const InputPathType * ptr ) + { m_Path = ptr; } + + /** Get the input path. */ + const InputPathType * GetInputPath() const + { return m_Path.GetPointer(); } + + + /** Evaluate the function. + * Subclasses must provide this method. */ + virtual TOutput Evaluate( ) const = 0; + + + /** Check if an index is inside the image buffer. + * \warning For efficiency, no validity checking of + * the input image is done. */ + virtual bool IsInsideBuffer( const IndexType & index ) const + { + for ( unsigned int j = 0; j < ImageDimension; j++ ) + { + if ( index[j] < m_StartIndex[j] ) { return false; }; + if ( index[j] > m_EndIndex[j] ) { return false; }; + } + return true; + } + + /** Check if a continuous index is inside the image buffer. + * \warning For efficiency, no validity checking of + * the input image is done. */ + virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const + { + for ( unsigned int j = 0; j < ImageDimension; j++ ) + { + if ( index[j] < m_StartContinuousIndex[j] ) { return false; }; + if ( index[j] > m_EndContinuousIndex[j] ) { return false; }; + } + return true; + } + + /** Check if a point is inside the image buffer. + * \warning For efficiency, no validity checking of + * the input image pointer is done. */ + virtual bool IsInsideBuffer( const PointType & point ) const + { + ContinuousIndexType index; + m_Image->TransformPhysicalPointToContinuousIndex( point, index ); + return this->IsInsideBuffer( index ); + } + + /** Convert point to nearest index. */ + void ConvertPointToNearestIndex( const PointType & point, + IndexType & index ) const + { + ContinuousIndexType cindex; + m_Image->TransformPhysicalPointToContinuousIndex( point, cindex ); + this->ConvertContinuousIndexToNearestIndex( cindex, index ); + } + + /** Convert continuous index to nearest index. */ + void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex, + IndexType & index ) const + { + typedef typename IndexType::IndexValueType ValueType; + for ( unsigned int j = 0; j < ImageDimension; j++ ) + { index[j] = static_cast<ValueType>( vnl_math_rnd( cindex[j] ) ); } + } + + itkGetConstReferenceMacro(StartIndex, IndexType); + itkGetConstReferenceMacro(EndIndex, IndexType); + + itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType); + itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType); + +protected: + PathFunction(); + ~PathFunction() {} + void PrintSelf(std::ostream& os, Indent indent) const; + + /** Const pointer to the input image. */ + InputImageConstPointer m_Image; + InputPathConstPointer m_Path; + + /** Cache some values for testing if indices are inside buffered region. */ + IndexType m_StartIndex; + IndexType m_EndIndex; + ContinuousIndexType m_StartContinuousIndex; + ContinuousIndexType m_EndContinuousIndex; + +private: + PathFunction(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbPathFunction.txx" +#endif + +#endif diff --git a/Code/Common/otbPathFunction.txx b/Code/Common/otbPathFunction.txx new file mode 100644 index 0000000000..3077bede40 --- /dev/null +++ b/Code/Common/otbPathFunction.txx @@ -0,0 +1,88 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Evaluate a function of an image over a specific path + $Id:$ + +=========================================================================*/ +#ifndef _otbPathFunction_txx +#define _otbPathFunction_txx + +#include "otbPathFunction.h" + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage,class TInputPath, class TOutput, class TCoordRep> +PathFunction<TInputImage, TInputPath,TOutput, TCoordRep> +::ImageFunction() +{ + m_Image = NULL; + m_Path = NULL; + m_StartIndex.Fill(0); + m_EndIndex.Fill(0); + m_StartContinuousIndex.Fill(0.0); + m_EndContinuousIndex.Fill(0.0); +} + + +/** + * Standard "PrintSelf" method + */ +template <class TInputImage,class TInputPath, class TOutput, class TCoordRep> +void +PathFunction<TInputImage,TInputPath, TOutput, TCoordRep> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf( os, indent ); + os << indent << "InputImage: " << m_Image.GetPointer() << std::endl; + os << indent << "InputPath: " << m_Path.GetPointer() << std::endl; + os << indent << "StartIndex: " << m_StartIndex << std::endl; + os << indent << "EndIndex: " << m_EndIndex << std::endl; + os << indent << "StartContinuousIndex: " << m_StartContinuousIndex << std::endl; + os << indent << "EndContinuousIndex: " << m_EndContinuousIndex << std::endl; +} + + +/** + * Initialize by setting the input image + */ +template <class TInputImage,class TInputPath, class TOutput, class TCoordRep> +void +PathFunction<TInputImage, TInputPath, TOutput, TCoordRep> +::SetInputImage( + const InputImageType * ptr ) +{ + // set the input image + m_Image = ptr; + + if ( ptr ) + { + typedef typename IndexType::IndexValueType IndexValueType; + typename InputImageType::SizeType size = ptr->GetBufferedRegion().GetSize(); + m_StartIndex = ptr->GetBufferedRegion().GetIndex(); + + for ( unsigned int j = 0; j < ImageDimension; j++ ) + { + m_EndIndex[j] = m_StartIndex[j] + + static_cast<IndexValueType>( size[j] ) - 1; + m_StartContinuousIndex[j] = static_cast<CoordRepType>( m_StartIndex[j] ); + m_EndContinuousIndex[j] = static_cast<CoordRepType>( m_EndIndex[j] ); + } + + } +} + + + +} // end namespace otb + +#endif + diff --git a/Code/FeatureExtraction/otbComplexMomentPathFunction.h b/Code/FeatureExtraction/otbComplexMomentPathFunction.h new file mode 100644 index 0000000000..2ad63c743c --- /dev/null +++ b/Code/FeatureExtraction/otbComplexMomentPathFunction.h @@ -0,0 +1,109 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Complex Geometric Moments Class of paths + $Id:$ + +=========================================================================*/ +#ifndef _otbComplexMomentPathFunction_h +#define _otbComplexMomentPathFunction_h + +#include "otbGeometricMomentPathFunction.h" + +#include <complex> + +namespace otb +{ + +/** + * \class ComplexMomentPathFunction + * \brief Calculate the complex moment value over a path list. + * + * The implemented equation is: + * + * \f[ c_{p,q}=\int\int_{D} (x+iy)^{p} \cdot (x-iy)^{q} \cdot f(x,y) \cdot + dx \cdot dy \f] + * + * With: + * + * - \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 + * - the path type + * - and the coordinate representation type (e.g. float or double). + * + * \ingroup ImageFunctions + */ +template < class TInputImage, + class TInputPath, + class TOutput = std::complex<double >, + class TCoordRep = float > +class ITK_EXPORT ComplexMomentPathFunction : + public GeometricMomentPathFunction<TInputImage, TInputPath, TOutput,TCoordRep> +{ +public: + /** Standard class typedefs. */ + typedef ComplexMomentPathFunction Self; + typedef GeometricMomentPathFunction<TInputImage,TInputPath, + TOutput,TCoordRep> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(ComplexMomentPathFunction, GeometricMomentPathFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** InputImageType typedef support. */ + typedef typename Superclass::InputType InputType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + + /** InputPathType typedef support. */ + typedef typename Superclass::InputPathType InputPathType; + typedef typename Superclass::InputPathConstPointer InputPathConstPointer; + + typedef TOutput ComplexType; + + /** Dimension of the underlying image. */ + itkStaticConstMacro(ImageDimension, unsigned int, + InputType::ImageDimension); + + /** Evalulate the function */ + virtual ComplexType Evaluate( ) const; + + itkSetMacro(P, unsigned int); + itkGetConstReferenceMacro(P, unsigned int); + itkSetMacro(Q, unsigned int); + itkGetConstReferenceMacro(Q, unsigned int); + +protected: + ComplexMomentPathFunction(); + ~ComplexMomentPathFunction(){}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ComplexMomentPathFunction( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented + + unsigned int m_P; + unsigned int m_Q; + +}; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbComplexMomentPathFunction.txx" +#endif + +#endif + diff --git a/Code/FeatureExtraction/otbComplexMomentPathFunction.txx b/Code/FeatureExtraction/otbComplexMomentPathFunction.txx new file mode 100644 index 0000000000..9575bce346 --- /dev/null +++ b/Code/FeatureExtraction/otbComplexMomentPathFunction.txx @@ -0,0 +1,140 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Geometric Moments Class of path + $Id:$ + +=========================================================================*/ +#ifndef _otbComplexMomentPathFunction_txx +#define _otbComplexMomentPathFunction_txx + +#include "otbComplexMomentPathFunction.h" +#include "itkImageRegionIterator.h" +#include "itkImage.h" +#include "itkConstNeighborhoodIterator.h" + +#include <complex> +namespace otb +{ + +/** + * Constructor + */ +template < class TInputImage, class TInputPath, class TOutput, class TCoordRep> +ComplexMomentPathFunction<TInputImage,TInputPath,TOutput,TCoordRep> +::ComplexMomentPathFunction() +{ + m_P = 0; + m_Q = 0; +} + +/** + * + */ +template < class TInputImage, class TInputPath, class TOutput, class TCoordRep> +void +ComplexMomentPathFunction<TInputImage,TInputPath,TOutput,TCoordRep> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os,indent); + os << indent << " p indice value : " << m_P << std::endl; + os << indent << " q indice value : " << m_Q << std::endl; +} + + +template < class TInputImage, class TInputPath, class TOutput, class TCoordRep> +typename ComplexMomentPathFunction<TInputImage,TInputPath, + TOutput,TCoordRep>::ComplexType +ComplexMomentPathFunction<TInputImage,TInputPath,TOutput,TCoordRep> +::Evaluate() const +{ + typename InputType::ConstPointer Image; + typename InputType::SizeType ImageSize; + + ComplexType Sum; + ComplexType ValP; + ComplexType ValQ; + IndexType IndexValue; + IndexType indexPos = index; + typename InputType::SizeType kernelSize; + + if( !this->GetInputImage() ) + { + return std::complex<float>(0.,0.); // A modifier + } + if( !this->GetInputPath() ) + { + return std::complex<float>(0.,0.); // A modifier + } + + + Image = this->GetInputImage(); + Path = this->GetInputPath(); + + ImageSize = this->GetInputImage()->GetBufferedRegion().GetSize(); + + VertexDebut = + + while() + + + if(m_NeighborhoodRadius<0) + { + indexPos[0] = ImageSize[0] / 2 ; + indexPos[1] = ImageSize[1] / 2; + + kernelSize[0] = indexPos[0]; + kernelSize[1] = indexPos[1]; + } + else + { + kernelSize.Fill( m_NeighborhoodRadius ); + } + + itk::ConstNeighborhoodIterator<InputType> + it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion()); + + // Set the iterator at the desired location + it.SetLocation(indexPos); + Sum = std::complex<float>(0.0,0.0); + + const unsigned int size = it.Size(); + for (unsigned int i = 0; i < size; ++i) + { + IndexValue = it.GetIndex(i); + ValP = std::complex<float>(1.0,0.0); + ValQ = std::complex<float>(1.0,0.0); + unsigned int p = m_P; + while(p>0) + { + ValP *= std::complex<float>(IndexValue[0], IndexValue[1]); + --p; + } + unsigned int q = m_Q; + while(q>0) + { + ValQ *= std::complex<float>(IndexValue[0], -IndexValue[1]); + --q; + } +// std::cout<< i <<"--> "<< IndexValue << " p:"<<ValP <<" Q: "<<ValQ; + + Sum += ( ValP * ValQ * std::complex<float>(static_cast<float>(it.GetPixel(i)),0.0) ); +// std::cout<< "Val Pixel: " << static_cast<float>(it.GetPixel(i)) <<" Result :" << Sum<<std::endl; + } + +// std::cout<<"Result dans la procedure: " <<Sum <<std::endl; + + return (static_cast<ComplexType>(Sum) ); + +#endif + +} + + +} // namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbGeometricMomentImageFunction.h b/Code/FeatureExtraction/otbGeometricMomentImageFunction.h index 1588a687de..baa8143297 100644 --- a/Code/FeatureExtraction/otbGeometricMomentImageFunction.h +++ b/Code/FeatureExtraction/otbGeometricMomentImageFunction.h @@ -5,8 +5,8 @@ Language : C++ Date : 17 mars 2006 Version : - Role : Geometric Moments Class of iamges - $Id$ + Role : Geometric Moments Class of images + $Id:$ =========================================================================*/ #ifndef _otbGeometricMomentImageFunction_h @@ -67,4 +67,3 @@ private: } // namespace otb #endif - diff --git a/Code/FeatureExtraction/otbGeometricMomentPathFunction.h b/Code/FeatureExtraction/otbGeometricMomentPathFunction.h new file mode 100644 index 0000000000..a2250d0a52 --- /dev/null +++ b/Code/FeatureExtraction/otbGeometricMomentPathFunction.h @@ -0,0 +1,73 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Geometric Moments Class of path + $Id:$ + +=========================================================================*/ +#ifndef _otbGeometricMomentPathFunction_h +#define _otbGeometricMomentPathFunction_h + +#include "otbPathFunction.h" + + +namespace otb +{ + +/** + * \class GeometricMomentPathFunction + * \brief Virtual class for the Geometric moments for an path function + * + * \ingroup PathFunctions + */ + +template < class TInputImage, + class TInputPath, + class TOutput = float, + class TCoordRep = float > +class ITK_EXPORT GeometricMomentPathFunction : + public itk::ImageFunction<TInputImage , TInputPath, TOutput, TCoordRep > +{ +public: + /** Standard class typedefs. */ + typedef GeometricMomentPathFunction Self; + typedef PathFunction< TInputImage, TInputPath, TOutput,TCoordRep > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(GeometricMomentPathFunction, PathFunction); + + + /** InputImageType typedef support. */ + typedef typename Superclass::InputType InputType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::InputPathType InputPathType; + typedef typename Superclass::InputPathConstPointer InputPathConstPointer; + + typedef TOutput OutputType; + + +protected: + GeometricMomentPathFunction() {}; + ~GeometricMomentPathFunction(){}; + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf( os, indent ); + } + +private: + GeometricMomentPathFunction( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented +}; + +} // namespace otb + +#endif + diff --git a/Code/FeatureExtraction/otbRealMomentPathFunction.h b/Code/FeatureExtraction/otbRealMomentPathFunction.h new file mode 100644 index 0000000000..deaf349863 --- /dev/null +++ b/Code/FeatureExtraction/otbRealMomentPathFunction.h @@ -0,0 +1,74 @@ +/*========================================================================= + + Programme : OTB (ORFEO ToolBox) + Auteurs : CS - P. Imbo + Language : C++ + Date : 22 mars 2006 + Version : + Role : Real Geometric Moments Class of Path + $Id:$ + +=========================================================================*/ +#ifndef _otbRealMomentPathFunction_h +#define _otbRealMomentPathFunction_h + +#include "otbGeometricMomentPathFunction.h" + + +namespace otb +{ + +/** + * \class RealMomentPathFunction + * \brief Virtual class for the Real moments for a path + * + * \ingroup PathFunctions + */ + +template < class TInputImage, + class TInputPath, + class TOutput = float, + class TCoordRep = float > +class ITK_EXPORT RealMomentPathFunction : + public GeometricMomentPathFunction<TInputImage,TInputPath, TOutput,TCoordRep > +{ +public: + /** Standard class typedefs. */ + typedef RealMomentPathFunction Self; + typedef GeometricMomentPathFunction< TInputImage, TInputPath, + TOutput,TCoordRep > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(RealMomentPathFunction, GeometricMomentPathFunction); + + + /** InputImageType typedef support. */ + typedef typename Superclass::InputType InputType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::InputPathType InputPathType; + typedef typename Superclass::InputPathConstPointer InputPathConstPointer; + + typedef TOutput OutputType; + + +protected: + RealMomentPathFunction() {}; + ~RealMomentPathFunction(){}; + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf( os, indent ); + } + +private: + RealMomentPathFunction( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented +}; + +} // namespace otb + +#endif + diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 611cc08e77..53302b614f 100755 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -12,25 +12,34 @@ SET(TOL 0.0) SET(BASICFILTERS_TESTS ${CXX_TEST_PATH}/otbBasicFiltersTests) -ADD_TEST(bfTuFiltreLee1CanalPoupees ${BASICFILTERS_TESTS} +ADD_TEST(bfTvFiltreLee1CanalPoupees ${BASICFILTERS_TESTS} + --compare-image ${TOL} ${BASELINE}/bfFiltreLee_05_05_04.png + ${TEMP}/bfFiltreLee_05_05_04.png otbLeeFilter ${INPUTDATA}/poupees_1canal.hd ${TEMP}/bfFiltreLee_05_05_04.png 05 05 4.0) -ADD_TEST(bfTuFiltreLee ${BASICFILTERS_TESTS} +ADD_TEST(bfTvFiltreLee ${BASICFILTERS_TESTS} + --compare-image ${TOL} ${BASELINE}/bfFiltreLee_05_05_12.png + ${TEMP}/bfFiltreLee_05_05_12.png otbLeeFilter ${INPUTDATA}/poupees.hd ${TEMP}/bfFiltreLee_05_05_12.png 05 05 12.0) + +# +# Filtre de FROST: +# -ADD_TEST(bfTuFiltreFrost ${BASICFILTERS_TESTS} +ADD_TEST(bfTvFiltreFrost ${BASICFILTERS_TESTS} + --compare-image ${TOL} ${BASELINE}/bfFiltreFrost_poupees_05_05_01.png + ${TEMP}/bfFiltreFrost_poupees_05_05_01.png otbFrostFilter ${INPUTDATA}/poupees.hd ${TEMP}/bfFiltreFrost_poupees_05_05_01.png 05 05 0.1) - # A enrichir SET(BasicFilters_SRCS otbLeeFilter.cxx diff --git a/Testing/Code/BasicFilters/otbFrostFilter.cxx b/Testing/Code/BasicFilters/otbFrostFilter.cxx index 0defb958d7..a342556b10 100644 --- a/Testing/Code/BasicFilters/otbFrostFilter.cxx +++ b/Testing/Code/BasicFilters/otbFrostFilter.cxx @@ -13,21 +13,116 @@ #pragma warning ( disable : 4786 ) #endif -#define MAIN +//#define MAIN + +#include "otbImageFileReader.h" +#include "otbFrostImageFilter.h" #include "itkExceptionObject.h" -#include "itkImage.h" #include "itkImageFileWriter.h" -#include <iostream> +#include "itkImage.h" +#include "itkRandomImageSource.h" +#include "itkMeanImageFilter.h" -// A supprimer -//#ifndef __otbCAIImageIO_h -//#define __otbCAIImageIO_h -//#endif -//#include "otbCAIImageIO.h" -#include "otbImageFileReader.h" -#include "otbFrostImageFilter.h" +int otbFrostFilterNew( int argc, char ** argv ) +{ + try + { + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; + const unsigned int Dimension = 2; + + typedef itk::Image< InputPixelType, Dimension > InputImageType; + typedef itk::Image< OutputPixelType, Dimension > OutputImageType; + + typedef otb::FrostImageFilter< InputImageType,OutputImageType > FilterType; + + FilterType::Pointer frost = FilterType::New(); + } + 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; +} + + +int otbFrostFilterTest( int argc, char ** argv ) +{ + + typedef itk::Image<float,2> FloatImage2DType; + + itk::RandomImageSource<FloatImage2DType>::Pointer random; + random = itk::RandomImageSource<FloatImage2DType>::New(); + random->SetMin(0.0); + random->SetMax(1000.0); + + unsigned long randomSize[2]; + randomSize[0] = randomSize[1] = 8; + random->SetSize(randomSize); + + float spacing[2] = {0.7, 2.1}; + random->SetSpacing( spacing ); + float origin[2] = {15, 400}; + random->SetOrigin( origin ); + + // Create a mean image + otb::FrostImageFilter<FloatImage2DType, FloatImage2DType>::Pointer frost; + frost = otb::FrostImageFilter<FloatImage2DType,FloatImage2DType>::New(); + frost->SetInput(random->GetOutput()); + + // define the neighborhood size used for the mean filter (5x5) + FloatImage2DType::SizeType neighRadius; + neighRadius[0] = 1; + neighRadius[1] = 1; + frost->SetRadius(neighRadius); + + // run the algorithm + frost->Update(); + + itk::ImageRegionIterator<FloatImage2DType> it; + it = itk::ImageRegionIterator<FloatImage2DType>(random->GetOutput(), + random->GetOutput()->GetBufferedRegion()); + std::cout << "Input image" << std::endl; + unsigned int i; + for (i=1; !it.IsAtEnd(); ++i, ++it) + { + std::cout << "\t" << it.Get(); + if ((i % 8) == 0) + { + std::cout << std::endl; + } + } + + std::cout << "Output image" << std::endl; + it = itk::ImageRegionIterator<FloatImage2DType>(frost->GetOutput(), + frost->GetOutput()->GetBufferedRegion()); + for (i=1; !it.IsAtEnd(); ++i, ++it) + { + std::cout << "\t" << it.Get(); + if ((i % 8) == 0) + { + std::cout << std::endl; + } + } + + // Test the itkGetConstReferenceMacro + const FloatImage2DType::SizeType & radius = frost->GetRadius(); + std::cout << "frost->GetRadius():" << radius << std::endl; + + return EXIT_SUCCESS; + +} + int otbFrostFilter( int argc, char ** argv ) diff --git a/Testing/Code/FeatureExtraction/otbComplexMomentPath.cxx b/Testing/Code/FeatureExtraction/otbComplexMomentPath.cxx index 5283e69029..038b2a7775 100644 --- a/Testing/Code/FeatureExtraction/otbComplexMomentPath.cxx +++ b/Testing/Code/FeatureExtraction/otbComplexMomentPath.cxx @@ -35,9 +35,9 @@ int otbComplexMomentPath( int argc, char ** argv ) typedef InputImageType::PointType ImagePointType; typedef otb::ImageFileReader< InputImageType > ReaderType; - typedef itk::PolyLineParametricPath< Dimension > PathType; - typedef std::complex<double> ComplexType - typedef otb::ComplexMomentPathFunction<InputImageType,PathType> CMType; + typedef itk::PolyLineParametricPath< Dimension > PathType; + typedef std::complex<double> ComplexType + typedef otb::ComplexMomentPathFunction<InputImageType,PathType,ComplexType> CMType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( inputFilename ); -- GitLab