diff --git a/Code/Common/otbVariableLengthVectorConverter.h b/Code/Common/otbVariableLengthVectorConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..fac00cf55ed0b8705217681a2e26394c81a94e13 --- /dev/null +++ b/Code/Common/otbVariableLengthVectorConverter.h @@ -0,0 +1,258 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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 __otbVariableLengthVectorConverter_h +#define __otbVariableLengthVectorConverter_h + +#include "itkProcessObject.h" +#include "itkVariableLengthVector.h" +#include "itkNumericTraits.h" +#include "itkExceptionObject.h" +#include "itkFixedArray.h" +#include "itkHistogram.h" + + +namespace otb +{ +/** + * \class VariableLengthVectorConverter + * \brief Convert any data container type into a VariableLengthVector. + * + * To be usable, the desired convertion must be implemented through + * partial specialisation mecanism. + * + */ + +//Base +template< class TInputType, class TPrecisionType = double > +class ITK_EXPORT VariableLengthVectorConverter : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef TInputType InputType; + + OutputType Convert (InputType input) + { + itkGenericExceptionMacro( << "Type Convertion Not Implemented." << std::endl ); + } + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Attempt to use inexistant implementation of the converter!" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +// Real Matrix +template< class TInternalInputType, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<TInternalInputType> >, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename std::vector<std::vector<TInternalInputType> > InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: std::vector<std::vector<RealType>> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +//Complex Matrix +template< class TInternalInputType, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename std::vector<std::vector<std::complex<TInternalInputType> > > InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: std::vector<std::vector<std::complex<RealType>>> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + + + +//Fixed Array +template< class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<itk::FixedArray<TInternalInputType, VArrayDimension>, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename itk::FixedArray<TInternalInputType, VArrayDimension> InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: itk::FixedArray<RealType, VArrayDimension> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +//Histogram +template< class TMeasurement, unsigned int VMeasurementVectorSize, class TFrequencyContainer, class TPrecisionType > +class ITK_EXPORT VariableLengthVectorConverter<itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer>, + TPrecisionType> : +public itk::ProcessObject +{ +public: + /** Standard class typedefs */ + typedef VariableLengthVectorConverter Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VariableLengthVectorConverter, ProcessObject); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TPrecisionType OutputPrecisionType; + typedef typename itk::VariableLengthVector<OutputPrecisionType> OutputType; + typedef typename itk::Statistics::Histogram<TMeasurement, + VMeasurementVectorSize, + TFrequencyContainer> InputType; + + OutputType Convert(InputType input); + +protected: + VariableLengthVectorConverter(){} + virtual ~VariableLengthVectorConverter(){} + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << "Converter: itk::Statistics::Histogram<RealType, VMeasurementVectorSize, TFrequencyContainer> => VariableLengthVector<RealType>" + << std::endl; + } + +private: + VariableLengthVectorConverter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +}// namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbVariableLengthVectorConverter.txx" +#endif + +#endif diff --git a/Code/Common/otbVariableLengthVectorConverter.txx b/Code/Common/otbVariableLengthVectorConverter.txx new file mode 100644 index 0000000000000000000000000000000000000000..16a84fd82a5fa6aedf4cb6100ddb4bd03ee1c7a4 --- /dev/null +++ b/Code/Common/otbVariableLengthVectorConverter.txx @@ -0,0 +1,133 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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 __otbVariableLengthVectorConverter_txx +#define __otbVariableLengthVectorConverter_txx + +#include "otbVariableLengthVectorConverter.h" +#include "itkNumericTraits.h" +#include <complex> + + +namespace otb +{ + +// Real Matrix +template< class TInternalInputType, class TPrecisionType > +typename VariableLengthVectorConverter< std::vector<std::vector<TInternalInputType> >, TPrecisionType> +::OutputType +VariableLengthVectorConverter< std::vector<std::vector<TInternalInputType> >, TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + p = input.size(); + q = input.at(0).size(); + + result.SetSize(p*q); + + for (unsigned int i=0; i<p; i++) + { + for (unsigned int j=0; j<q; j++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j)); + rsltIdx ++; + } + } + + return result; +} + +// Complex Matrix +template< class TInternalInputType, class TPrecisionType > +typename VariableLengthVectorConverter< std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> +::OutputType +VariableLengthVectorConverter< std::vector<std::vector<std::complex<TInternalInputType> > >, + TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + p = input.size(); + q = input.at(0).size(); + + result.SetSize(p*q*2); + + for (unsigned int i=0; i<p; i++) + { + for (unsigned int j=0; j<q; j++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).real()); + rsltIdx ++; + result[rsltIdx] = static_cast<OutputPrecisionType>(input.at(i).at(j).imag()); + rsltIdx ++; + } + } + + return result; +} + +// Fixed Array +template< class TInternalInputType, unsigned int VArrayDimension, class TPrecisionType > +typename VariableLengthVectorConverter< itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType> +::OutputType +VariableLengthVectorConverter< itk::FixedArray<TInternalInputType, VArrayDimension>, TPrecisionType> +::Convert(InputType input) +{ + unsigned int p, q, rsltIdx = 0; + OutputType result; + + result.SetSize(VArrayDimension); + + for (unsigned int i=0; i<VArrayDimension; i++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input[i]); + rsltIdx ++; + } + + return result; +} + +// Histogram +template< class TMeasurement, unsigned int VMeasurementVectorSize, class TFrequencyContainer, class TPrecisionType > +typename VariableLengthVectorConverter< itk::Statistics::Histogram<TMeasurement, VMeasurementVectorSize, TFrequencyContainer>, TPrecisionType> +::OutputType +VariableLengthVectorConverter< itk::Statistics::Histogram<TMeasurement, VMeasurementVectorSize, TFrequencyContainer>, TPrecisionType> +::Convert(InputType input) +{ + unsigned int nbBins, rsltIdx = 0; + OutputType result; + + nbBins = input.GetSize(); + + result.SetSize(nbBins); + + for (unsigned int i=0; i<nbBins; i++) + { + result[rsltIdx] = static_cast<OutputPrecisionType>(input.GetFrequency(i)); + rsltIdx ++; + } + + return result; +} + +} // namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbComplexMomentsImageFunction.h b/Code/FeatureExtraction/otbComplexMomentsImageFunction.h index 9a6314c07fb85f814379917d0f46cc6706dc046d..290c27a544d04cdbe166731c365721388d552acf 100644 --- a/Code/FeatureExtraction/otbComplexMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbComplexMomentsImageFunction.h @@ -80,6 +80,8 @@ public: typedef double ScalarRealType; typedef typename std::complex<ScalarRealType> ScalarComplexType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h b/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h index 422d83222ecb4cdd3abb832bab72949f71c8d1bd..80170e12224793fe2afce524fa7b4ac94bbaaa4b 100644 --- a/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbFlusserMomentsImageFunction.h @@ -93,6 +93,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h b/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h index f3600a3d84b0c0c703ba81dff23087f0827c4d4f..fc0c95a649cfa054af2ac82834358d373dff44f1 100644 --- a/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h +++ b/Code/FeatureExtraction/otbFourierMellinDescriptorsImageFunction.h @@ -89,6 +89,8 @@ public: typedef typename std::complex<ScalarRealType> ScalarComplexType; typedef typename std::vector< std::vector< ScalarComplexType > > ComplexType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbHuMomentsImageFunction.h b/Code/FeatureExtraction/otbHuMomentsImageFunction.h index 6428f41d356a3aa11dacb784d81261f106f1ca74..954f5437fb44cd0e8650973b1510549ca9a8eb0c 100644 --- a/Code/FeatureExtraction/otbHuMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbHuMomentsImageFunction.h @@ -89,6 +89,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.h b/Code/FeatureExtraction/otbImageFunctionAdaptor.h new file mode 100644 index 0000000000000000000000000000000000000000..bf392fddfc0a78416ab371fecffbe7685544a6ff --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.h @@ -0,0 +1,122 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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 __otbImageFunctionAdaptor_h +#define __otbImageFunctionAdaptor_h + +#include "itkImageFunction.h" +#include "itkNumericTraits.h" + +#include "otbVariableLengthVectorConverter.h" + + +#include <complex> + +namespace otb +{ + + +template< class TInternalImageFunctionType > +class ITK_EXPORT ImageFunctionAdaptor : + public itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > +{ + public: + // Standard class typedefs. // + typedef ImageFunctionAdaptor Self; + typedef itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > + Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + // Run-time type information (and related methods). // + itkTypeMacro(ImageFunctionAdaptor, ImageFunction); + + // Method for creation through the object factory. // + itkNewMacro(Self); + + // InputImageType typedef support. // + typedef typename TInternalImageFunctionType::InputImageType InputImageType; + typedef typename TInternalImageFunctionType::CoordRepType CoordRepType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::OutputType OutputType; + typedef typename OutputType::ValueType OutputValueType; + + // InternalImageFunction related typedefs // + typedef TInternalImageFunctionType InternalImageFunctionType; + typedef typename InternalImageFunctionType::OutputType InternalImageFunctionOutputType; + + // Converter related typedefs // + typedef VariableLengthVectorConverter<InternalImageFunctionOutputType, double> ConverterType; + + + // Dimension of the underlying image. // + itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + + // Evalulate the function at specified index // + virtual OutputType EvaluateAtIndex(const IndexType& index) const; + + // Evaluate the function at non-integer positions // + virtual OutputType Evaluate(const PointType& point) const + { + IndexType index; + this->ConvertPointToNearestIndex(point, index); + return this->EvaluateAtIndex(index); + } + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex(cindex, index); + return this->EvaluateAtIndex(index); + } + + // Accessors // + itkGetConstMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + itkSetMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + +protected: + ImageFunctionAdaptor(); + virtual ~ImageFunctionAdaptor() {} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageFunctionAdaptor(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + // Internal Image Function // + typename InternalImageFunctionType::Pointer m_InternalImageFunction; + // Converter // + typename ConverterType::Pointer m_Converter; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageFunctionAdaptor.txx" +#endif + +#endif diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.txx b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx new file mode 100644 index 0000000000000000000000000000000000000000..62a1437d1419ee56559017189bba046b0e1feb1b --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx @@ -0,0 +1,58 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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 __otbImageFunctionAdaptor_txx +#define __otbImageFunctionAdaptor_txx + +#include "otbImageFunctionAdaptor.h" + +namespace otb +{ +template< class TInternalImageFunctionType > +ImageFunctionAdaptor< TInternalImageFunctionType > +::ImageFunctionAdaptor() +{ + m_InternalImageFunction = InternalImageFunctionType::New(); + m_Converter = ConverterType::New(); +} + +template< class TInternalImageFunctionType > +void +ImageFunctionAdaptor< TInternalImageFunctionType > +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "Internal Image Function: " << m_InternalImageFunction << std::endl; +} + +template< class TInternalImageFunctionType > +typename ImageFunctionAdaptor< TInternalImageFunctionType >::OutputType +ImageFunctionAdaptor< TInternalImageFunctionType > +::EvaluateAtIndex(const IndexType& index) const +{ + OutputType result; + this->GetInternalImageFunction()->SetInputImage(this->GetInputImage()); + InternalImageFunctionOutputType tmpResult = this->GetInternalImageFunction()->EvaluateAtIndex(index); + result = m_Converter->Convert(tmpResult); + + return result; +} + + +} // end namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbLocalHistogramImageFunction.h b/Code/FeatureExtraction/otbLocalHistogramImageFunction.h index 747315729ef0fffbbf26d69ed52c8493615b5a5c..fe4253665c364ff424470ed8e27a5d0c46fde565 100644 --- a/Code/FeatureExtraction/otbLocalHistogramImageFunction.h +++ b/Code/FeatureExtraction/otbLocalHistogramImageFunction.h @@ -71,6 +71,8 @@ public: typedef typename HistogramType::Pointer HistogramPointer; typedef typename GeneratorType::Pointer GeneratorPointer; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h b/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h index 4bb775f9f94e06d2df52f68eb0164ffd334b7a9c..f7cc6d5454ae12ab416c905a559f3ccf5bc5ea12 100644 --- a/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbRadiometricMomentsImageFunction.h @@ -72,6 +72,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef typename OutputType::ValueType ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Code/FeatureExtraction/otbRealMomentsImageFunction.h b/Code/FeatureExtraction/otbRealMomentsImageFunction.h index 39d297cec9a6b04b3938f92da7dae5fb8578c143..1534dc35ec9d906398a63d2d0d4e32157d81548d 100644 --- a/Code/FeatureExtraction/otbRealMomentsImageFunction.h +++ b/Code/FeatureExtraction/otbRealMomentsImageFunction.h @@ -67,6 +67,8 @@ public: typedef typename Superclass::OutputType OutputType; typedef float ScalarRealType; + typedef TCoordRep CoordRepType; + /** Dimension of the underlying image. */ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index f5ba7d62e4afc98478ed0ea00a33e1f1c5fdb3b3..9630fc3714d515ffa323c91e629e4a349469e294 100644 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -919,7 +919,7 @@ otbUnaryFunctorWithIndexImageFilter # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests12 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ---------------- otbParser ---------------------# +# ---------------- otbParser --------------------- # ADD_TEST(coTuParser ${COMMON_TESTS12} otbParserTestNew ) @@ -928,6 +928,14 @@ otbUnaryFunctorWithIndexImageFilter otbParserTest ) +# ---------------- otbVariableLengthVectorConverter --------------------- # +ADD_TEST(coTuVariableLengthVectorConverter ${COMMON_TESTS12} + otbVariableLengthVectorConverterNew + ) + +#ADD_TEST(coTvVariableLengthVectorConverter ${COMMON_TESTS12} +# otbVariableLengthVectorConverter +# ) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1087,6 +1095,7 @@ otbUnaryFunctorWithIndexImageFilter.cxx SET(BasicCommon_SRCS12 otbCommonTests12.cxx otbParserTest.cxx +otbVariableLengthVectorConverter.cxx ) diff --git a/Testing/Code/Common/otbCommonTests12.cxx b/Testing/Code/Common/otbCommonTests12.cxx index f11a9e0d157059ec6a313038d2676948567b9706..28e89d576352973d8852aa9f44ef765e42109a30 100644 --- a/Testing/Code/Common/otbCommonTests12.cxx +++ b/Testing/Code/Common/otbCommonTests12.cxx @@ -28,4 +28,6 @@ void RegisterTests() { REGISTER_TEST(otbParserTestNew); REGISTER_TEST(otbParserTest); + REGISTER_TEST(otbVariableLengthVectorConverterNew); + //REGISTER_TEST(otbVariableLengthVectorConverter); } diff --git a/Testing/Code/Common/otbVariableLengthVectorConverter.cxx b/Testing/Code/Common/otbVariableLengthVectorConverter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d3e9a32ce1a0610f70ef9199274d91cc0bace2a1 --- /dev/null +++ b/Testing/Code/Common/otbVariableLengthVectorConverter.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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. + +=========================================================================*/ +#include "itkExceptionObject.h" +#include <cstdlib> +#include <cmath> + +#include "otbVariableLengthVectorConverter.h" + +int otbVariableLengthVectorConverterNew(int argc, char * argv[]) +{ + typedef itk::VariableLengthVector<double> InputType0; + typedef std::vector< std::vector< double > > InputType1; + typedef std::vector< std::vector< std::complex< double > > > InputType2; + typedef itk::FixedArray<double> InputType3; + + typedef float PrecisionType; + + typedef otb::VariableLengthVectorConverter<InputType0, PrecisionType> + ConverterType0; + typedef otb::VariableLengthVectorConverter<InputType1, PrecisionType> + ConverterType1; + typedef otb::VariableLengthVectorConverter<InputType2, PrecisionType> + ConverterType2; + typedef otb::VariableLengthVectorConverter<InputType3, PrecisionType> + ConverterType3; + + // Instantiating object + ConverterType0::Pointer converter0 = ConverterType0::New(); + ConverterType1::Pointer converter1 = ConverterType1::New(); + ConverterType2::Pointer converter2 = ConverterType2::New(); + ConverterType3::Pointer converter3 = ConverterType3::New(); + + std::cout << converter0 << std::endl; + std::cout << converter1 << std::endl; + std::cout << converter2 << std::endl; + std::cout << converter3 << std::endl; + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 560bcf869530627cf44fba8f1214cefa96728ca2..12b13c2b26f4b4e0cb5355e71882cd2c5119a5bb 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1504,12 +1504,12 @@ ADD_TEST(feTuLocalHistogramImageFunctionTest ${FEATUREEXTRACTION_TESTS16} # ------- otb::ImageFunctionAdapter ------------- -ADD_TEST(feTuImageFunctionAdapterNew ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapterNew +ADD_TEST(feTuImageFunctionAdaptorNew ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptorNew ) -ADD_TEST(feTvImageFunctionAdapter ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapter +ADD_TEST(feTvImageFunctionAdaptor ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptor ${INPUTDATA}/poupees.png ) @@ -1722,7 +1722,7 @@ otbFeatureExtractionTests16.cxx otbFourierMellinDescriptors.cxx otbLocalHistogramImageFunctionNew.cxx otbLocalHistogramImageFunctionTest.cxx -otbImageFunctionAdapter.cxx +otbImageFunctionAdaptor.cxx otbMetaImageFunction.cxx ) diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx index 0b1ddb8e18db845756e4f2828bbf52142cf9ec51..4ce2d662b6c6c19970ed23327ab6483f78fe0892 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx @@ -32,8 +32,8 @@ void RegisterTests() REGISTER_TEST(otbFourierMellinDescriptorsRotationInvariant); REGISTER_TEST(otbLocalHistogramImageFunctionNew); REGISTER_TEST(otbLocalHistogramImageFunctionTest); - REGISTER_TEST(otbImageFunctionAdapterNew); - REGISTER_TEST(otbImageFunctionAdapter); + REGISTER_TEST(otbImageFunctionAdaptorNew); + REGISTER_TEST(otbImageFunctionAdaptor); REGISTER_TEST(otbMetaImageFunctionNew); REGISTER_TEST(otbMetaImageFunction); } diff --git a/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx b/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d5d3d6e55144f4859ed44f35eeb7d8f6074c062f --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbImageFunctionAdaptor.cxx @@ -0,0 +1,306 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt 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. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingMinMaxImageFilter.h" + +#include "otbImageFunctionAdaptor.h" + +#include "otbFourierMellinDescriptorsImageFunction.h" +#include "otbRealMomentsImageFunction.h" +#include "otbComplexMomentsImageFunction.h" +#include "otbFlusserMomentsImageFunction.h" +#include "otbHuMomentsImageFunction.h" +#include "otbRadiometricMomentsImageFunction.h" +#include "otbLocalHistogramImageFunction.h" + + +int otbImageFunctionAdaptorNew(int argc, char * argv[]) +{ + typedef double InputPixelType; + const unsigned int Dimension = 2; + + typedef otb::Image<InputPixelType, Dimension> InputImageType; + + typedef otb::FourierMellinDescriptorsImageFunction<InputImageType> FMDFunctionType; + typedef otb::RealMomentsImageFunction<InputImageType> RMFunctionType; + typedef otb::ComplexMomentsImageFunction<InputImageType> CMFunctionType; + typedef otb::FlusserMomentsImageFunction<InputImageType> FMFunctionType; + typedef otb::HuMomentsImageFunction<InputImageType> HMFunctionType; + typedef otb::RadiometricMomentsImageFunction<InputImageType> RaMFunctionType; + typedef otb::LocalHistogramImageFunction<InputImageType> LHFunctionType; + + typedef otb::ImageFunctionAdaptor<FMDFunctionType> FMDImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RMFunctionType> RMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<CMFunctionType> CMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<FMFunctionType> FMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<HMFunctionType> HMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RaMFunctionType> RaMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<LHFunctionType> LHImageFunctionAdaptorType; + + // Instantiating objects + FMDImageFunctionAdaptorType::Pointer FMDadaptedFunction = FMDImageFunctionAdaptorType::New(); + std::cout << FMDadaptedFunction << std::endl; + RMImageFunctionAdaptorType::Pointer RMadaptedFunction = RMImageFunctionAdaptorType::New(); + std::cout << RMadaptedFunction << std::endl; + CMImageFunctionAdaptorType::Pointer CMadaptedFunction = CMImageFunctionAdaptorType::New(); + std::cout << CMadaptedFunction << std::endl; + FMImageFunctionAdaptorType::Pointer FMadaptedFunction = FMImageFunctionAdaptorType::New(); + std::cout << FMadaptedFunction << std::endl; + HMImageFunctionAdaptorType::Pointer HMadaptedFunction = HMImageFunctionAdaptorType::New(); + std::cout << HMadaptedFunction << std::endl; + RaMImageFunctionAdaptorType::Pointer RaMadaptedFunction = RaMImageFunctionAdaptorType::New(); + std::cout << RaMadaptedFunction << std::endl; + //LHImageFunctionAdaptorType::Pointer LHadaptedFunction = LHImageFunctionAdaptorType::New(); + //std::cout << LHadaptedFunction << std::endl; + + return EXIT_SUCCESS; +} + +int otbImageFunctionAdaptor(int argc, char * argv[]) +{ + const char * inputFilename = argv[1]; + + typedef double InputPixelType; + const unsigned int Dimension = 2; + unsigned int rsltIdx = 0; + + typedef otb::Image<InputPixelType, Dimension> InputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::StreamingMinMaxImageFilter<InputImageType> MinMaxFilterType; + + typedef otb::FourierMellinDescriptorsImageFunction<InputImageType> FMDFunctionType; + typedef otb::RealMomentsImageFunction<InputImageType> RMFunctionType; + typedef otb::ComplexMomentsImageFunction<InputImageType> CMFunctionType; + typedef otb::FlusserMomentsImageFunction<InputImageType> FMFunctionType; + typedef otb::HuMomentsImageFunction<InputImageType> HMFunctionType; + typedef otb::RadiometricMomentsImageFunction<InputImageType> RaMFunctionType; + typedef otb::LocalHistogramImageFunction<InputImageType> LHFunctionType; + + typedef otb::ImageFunctionAdaptor<FMDFunctionType> FMDImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RMFunctionType> RMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<CMFunctionType> CMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<FMFunctionType> FMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<HMFunctionType> HMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<RaMFunctionType> RaMImageFunctionAdaptorType; + typedef otb::ImageFunctionAdaptor<LHFunctionType> LHImageFunctionAdaptorType; + + // Instantiating objects + ReaderType::Pointer reader = ReaderType::New(); + MinMaxFilterType::Pointer filter = MinMaxFilterType::New(); + + FMDFunctionType::Pointer FMDFunction = FMDFunctionType::New(); + RMFunctionType::Pointer RMFunction = RMFunctionType::New(); + CMFunctionType::Pointer CMFunction = CMFunctionType::New(); + FMFunctionType::Pointer FMFunction = FMFunctionType::New(); + HMFunctionType::Pointer HMFunction = HMFunctionType::New(); + RaMFunctionType::Pointer RaMFunction = RaMFunctionType::New(); + LHFunctionType::Pointer LHFunction = LHFunctionType::New(); + + FMDImageFunctionAdaptorType::Pointer FMDadaptedFunction = FMDImageFunctionAdaptorType::New(); + RMImageFunctionAdaptorType::Pointer RMadaptedFunction = RMImageFunctionAdaptorType::New(); + CMImageFunctionAdaptorType::Pointer CMadaptedFunction = CMImageFunctionAdaptorType::New(); + FMImageFunctionAdaptorType::Pointer FMadaptedFunction = FMImageFunctionAdaptorType::New(); + HMImageFunctionAdaptorType::Pointer HMadaptedFunction = HMImageFunctionAdaptorType::New(); + RaMImageFunctionAdaptorType::Pointer RaMadaptedFunction = RaMImageFunctionAdaptorType::New(); + LHImageFunctionAdaptorType::Pointer LHadaptedFunction = LHImageFunctionAdaptorType::New(); + + reader->SetFileName(inputFilename); + filter->SetInput(reader->GetOutput()); + filter->Update(); + + InputImageType::IndexType index; + index[0] = 100; + index[1] = 100; + + // Content testing + double error = 0.0; + + FMDFunction->SetInputImage(reader->GetOutput()); + FMDFunction->SetNeighborhoodRadius(5); + FMDFunction->SetPmax(5); + FMDFunction->SetQmax(5); + FMDFunctionType::OutputType resultFMD = FMDFunction->EvaluateAtIndex(index); + + FMDadaptedFunction->SetInputImage(reader->GetOutput()); + FMDadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + FMDadaptedFunction->GetInternalImageFunction()->SetPmax(5); + FMDadaptedFunction->GetInternalImageFunction()->SetQmax(5); + FMDImageFunctionAdaptorType::OutputType resultAdaptedFMD = FMDadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedFMD[rsltIdx] - resultFMD.at(i).at(j)), 2); + + std::cout << "resultAdaptedFMD : " << resultAdaptedFMD[rsltIdx] + << "\t - resultFMD : " << resultFMD.at(i).at(j) << std::endl; + rsltIdx ++; + } + } + + RMFunction->SetInputImage(reader->GetOutput()); + RMFunction->SetNeighborhoodRadius(5); + RMFunction->SetPmax(5); + RMFunction->SetQmax(5); + RMFunctionType::OutputType resultRM = RMFunction->EvaluateAtIndex(index); + + RMadaptedFunction->SetInputImage(reader->GetOutput()); + RMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + RMadaptedFunction->GetInternalImageFunction()->SetPmax(5); + RMadaptedFunction->GetInternalImageFunction()->SetQmax(5); + RMImageFunctionAdaptorType::OutputType resultAdaptedRM = RMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedRM[rsltIdx] - resultRM.at(i).at(j)), 2); + + std::cout << "resultAdaptedRM : " << resultAdaptedRM[rsltIdx] + << "\t - resultRM : " << resultRM.at(i).at(j) << std::endl; + rsltIdx ++; + } + } + + CMFunction->SetInputImage(reader->GetOutput()); + CMFunction->SetNeighborhoodRadius(5); + CMFunction->SetPmax(5); + CMFunction->SetQmax(5); + CMFunctionType::OutputType resultCM = CMFunction->EvaluateAtIndex(index); + + CMadaptedFunction->SetInputImage(reader->GetOutput()); + CMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + CMadaptedFunction->GetInternalImageFunction()->SetPmax(5); + CMadaptedFunction->GetInternalImageFunction()->SetQmax(5); + CMImageFunctionAdaptorType::OutputType resultAdaptedCM = CMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<=5; i++) + { + for (unsigned int j=0; j<=5; j++) + { + error += vcl_pow(vcl_abs(resultAdaptedCM[rsltIdx] - resultCM.at(i).at(j).real()), 2); + std::cout << "resultAdaptedCM : (" << resultAdaptedCM[rsltIdx] + << "," << resultAdaptedCM[rsltIdx+1] << ")" + << "\t - resultCM : " << resultCM.at(i).at(j) << std::endl; + rsltIdx ++; + error += vcl_pow(vcl_abs(resultAdaptedCM[rsltIdx] - resultCM.at(i).at(j).imag()), 2); + rsltIdx ++; + } + } + + FMFunction->SetInputImage(reader->GetOutput()); + FMFunction->SetNeighborhoodRadius(5); + FMFunctionType::OutputType resultFM = FMFunction->EvaluateAtIndex(index); + + FMadaptedFunction->SetInputImage(reader->GetOutput()); + FMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + FMImageFunctionAdaptorType::OutputType resultAdaptedFM = FMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<11; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedFM[rsltIdx] - resultFM[i]), 2); + + std::cout << "resultAdaptedFM : " << resultAdaptedFM[rsltIdx] + << "\t - resultFM : " << resultFM[i] << std::endl; + rsltIdx ++; + } + + HMFunction->SetInputImage(reader->GetOutput()); + HMFunction->SetNeighborhoodRadius(5); + HMFunctionType::OutputType resultHM = HMFunction->EvaluateAtIndex(index); + + HMadaptedFunction->SetInputImage(reader->GetOutput()); + HMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + HMImageFunctionAdaptorType::OutputType resultAdaptedHM = HMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<7; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedHM[rsltIdx] - resultHM[i]), 2); + + std::cout << "resultAdaptedHM : " << resultAdaptedHM[rsltIdx] + << "\t - resultHM : " << resultHM[i] << std::endl; + rsltIdx ++; + } + + RaMFunction->SetInputImage(reader->GetOutput()); + RaMFunction->SetNeighborhoodRadius(5); + RaMFunctionType::OutputType resultRaM = RaMFunction->EvaluateAtIndex(index); + + RaMadaptedFunction->SetInputImage(reader->GetOutput()); + RaMadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + RaMImageFunctionAdaptorType::OutputType resultAdaptedRaM = RaMadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<4; i++) + { + error += vcl_pow(vcl_abs(resultAdaptedRaM[rsltIdx] - resultRaM[i]), 2); + + std::cout << "resultAdaptedRaM : " << resultAdaptedRaM[rsltIdx] + << "\t - resultRaM : " << resultRaM[i] << std::endl; + rsltIdx ++; + } + + LHFunction->SetInputImage(reader->GetOutput()); + LHFunction->SetNeighborhoodRadius(5); + LHFunction->SetNumberOfHistogramBins(64); + LHFunction->SetHistogramMin(filter->GetMinimum()); + LHFunction->SetHistogramMax(filter->GetMaximum()); + LHFunctionType::OutputType resultLH = LHFunction->EvaluateAtIndex(index); + + LHadaptedFunction->SetInputImage(reader->GetOutput()); + LHadaptedFunction->GetInternalImageFunction()->SetNeighborhoodRadius(5); + LHadaptedFunction->GetInternalImageFunction()->SetNumberOfHistogramBins(64); + LHadaptedFunction->GetInternalImageFunction()->SetHistogramMin(filter->GetMinimum()); + LHadaptedFunction->GetInternalImageFunction()->SetHistogramMax(filter->GetMaximum()); + LHImageFunctionAdaptorType::OutputType resultAdaptedLH = LHadaptedFunction->EvaluateAtIndex(index); + + rsltIdx = 0; + for (unsigned int i=0; i<64; i++) + { + error += vcl_pow(vcl_abs( resultAdaptedLH[rsltIdx] - resultLH->GetFrequency(i)), 2); + + std::cout << "resultAdaptedLH : " << resultAdaptedLH[rsltIdx] + << "\t - resultLH : " << resultLH->GetFrequency(i) << std::endl; + rsltIdx ++; + } + + error = vcl_sqrt(error); + std::cout << std::endl << "Error : " << error << std::endl + << std::endl; + + if (error > 1E-3) + { + itkGenericExceptionMacro( << "Error = " << error + << " > 1E-9 -> TEST FAILLED" << std::endl ); + } + + return EXIT_SUCCESS; +} +