From 342e502fc61dd620a15b48b6da701948c7f018f9 Mon Sep 17 00:00:00 2001 From: Guillaume Borrut <guillaume.borrut@c-s.fr> Date: Fri, 6 Feb 2009 16:28:01 +0100 Subject: [PATCH] ENH: Adding GEMI AVI functors and testing. Adding RAndGAndNIRVegetationIndexImage Filters. --- ...nelRAndGAndNIRVegetationIndexImageFilter.h | 111 +++++++ ...otbRAndGAndNIRVegetationIndexImageFilter.h | 84 ++++++ Code/Radiometry/otbVegetationIndex.h | 279 +++++++++++++++++- Testing/Code/Radiometry/CMakeLists.txt | 154 +++++++++- ...lRAndGAndNIRVegetationIndexImageFilter.cxx | 77 +++++ ...IRAndGAndNIRVegetationIndexImageFilter.cxx | 88 ++++++ ...ndGAndNIRVegetationIndexImageFilterNew.cxx | 37 +++ ...annelRAndNIRVegetationIndexImageFilter.cxx | 15 + ...ndGAndNIRVegetationIndexImageFilterNew.cxx | 43 +++ .../otbRAndNIRVegetationIndexImageFilter.cxx | 15 + .../Code/Radiometry/otbRadiometryTests4.cxx | 4 + .../Code/Radiometry/otbRadiometryTests5.cxx | 37 +++ ...annelRAndNIRVegetationIndexImageFilter.cxx | 70 +++++ ...bWDVIRAndNIRVegetationIndexImageFilter.cxx | 75 +++++ 14 files changed, 1081 insertions(+), 8 deletions(-) create mode 100644 Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h create mode 100644 Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilter.h create mode 100644 Testing/Code/Radiometry/otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx create mode 100644 Testing/Code/Radiometry/otbAVIRAndGAndNIRVegetationIndexImageFilter.cxx create mode 100644 Testing/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew.cxx create mode 100644 Testing/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilterNew.cxx create mode 100644 Testing/Code/Radiometry/otbRadiometryTests5.cxx create mode 100644 Testing/Code/Radiometry/otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter.cxx create mode 100644 Testing/Code/Radiometry/otbWDVIRAndNIRVegetationIndexImageFilter.cxx diff --git a/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h b/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h new file mode 100644 index 0000000000..36c698be94 --- /dev/null +++ b/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h @@ -0,0 +1,111 @@ +/*========================================================================= + + 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 __otbMultiChannelRAndGAndNIRVegetationIndexImageFilter_h +#define __otbMultiChannelRAndGAndNIRVegetationIndexImageFilter_h + +#include "itkUnaryFunctorImageFilter.h" +#include "itkImageRegionIteratorWithIndex.h" +#include "otbVegetationIndex.h" + +namespace otb +{ + +/** \class MultiChannelRAndGAndNIRVegetationIndexImageFilter + * \brief Implements mutli channel R and G and NIR pixel-wise generic vegetation index operation on one vector image. + * + * This class is parameterized over the type of the input image and + * the type of the output image. It is also parameterized by the + * operation to be applied, using a Functor style. + * + * \sa UnaryFunctorImageFilter + * + */ +template <class TInputImage, class TOutputImage, + class TFunction = Functor::AVI< typename TInputImage::InternalPixelType, + typename TInputImage::InternalPixelType, + typename TInputImage::InternalPixelType, + typename TOutputImage::PixelType> > +class ITK_EXPORT MultiChannelRAndGAndNIRVegetationIndexImageFilter + : public itk::UnaryFunctorImageFilter<TInputImage,TOutputImage,TFunction> +{ +public: + /** Standard class typedefs. */ + typedef MultiChannelRAndGAndNIRVegetationIndexImageFilter Self; + typedef itk::UnaryFunctorImageFilter<TInputImage,TOutputImage,TFunction> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MultiChannelRAndGAndNIRVegetationIndexImageFilter, UnaryFunctorImageFilter); + + /** Some typedefs. */ + typedef TFunction FunctorType; + + /** Set/Get the red channel index. Value must be in [1...[ */ + itkSetMacro(RedIndex,unsigned int); + itkGetMacro(RedIndex,unsigned int); + /** Set/Get the green channel index. Value must be in [1...[ */ + itkSetMacro(GreenIndex,unsigned int); + itkGetMacro(GreenIndex,unsigned int); + /** Set/Get the nir channel index. Value must be in [1...[ */ + itkSetMacro(NIRIndex,unsigned int); + itkGetMacro(NIRIndex,unsigned int); + +protected: + /// Constructor + MultiChannelRAndGAndNIRVegetationIndexImageFilter(): m_RedIndex(3),m_GreenIndex(1),m_NIRIndex(4) {}; + /// Destructor + virtual ~MultiChannelRAndGAndNIRVegetationIndexImageFilter() {}; + /// Before generating data, set functor parameters + virtual void BeforeThreadedGenerateData() + { + if(m_RedIndex < 1 || m_GreenIndex < 1 || m_NIRIndex < 1) + { + itkExceptionMacro(<<"Channel indices must belong to range [1, ...["); + } + this->GetFunctor().SetRedIndex(m_RedIndex); + this->GetFunctor().SetGreenIndex(m_GreenIndex); + this->GetFunctor().SetNIRIndex(m_NIRIndex); + } + /// PrintSelf + void PrintSelf(std::ostream& os, itk::Indent indent) const + { + this->Superclass::PrintSelf(os,indent); + os << indent << "Red index: "<<m_RedIndex<<std::endl; + os << indent << "Green index: "<<m_GreenIndex<<std::endl; + os << indent << "NIR index: "<<m_NIRIndex<<std::endl; + } + +private: + MultiChannelRAndGAndNIRVegetationIndexImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + /** Red channel index */ + unsigned int m_RedIndex; + /** Green channel index */ + unsigned int m_GreenIndex; + /** NIR channel index */ + unsigned int m_NIRIndex; +}; + +} // end namespace otb + +#endif diff --git a/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilter.h b/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilter.h new file mode 100644 index 0000000000..4061f13d4e --- /dev/null +++ b/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilter.h @@ -0,0 +1,84 @@ +/*========================================================================= + + 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 __otbRAndGAndNIRVegetationIndexImageFilter_h +#define __otbRAndGAndNIRVegetationIndexImageFilter_h + +#include "itkTernaryFunctorImageFilter.h" +#include "otbVegetationIndex.h" + +namespace otb +{ + +/** \class RAndGAndNIRVegetationIndexImageFilter + * \brief + * + */ + +template <class TInputImageR, class TInputImageG, class TInputImageNIR, class TOutputImage, +class TFunction = Functor::ARVI< typename TInputImageR::PixelType, +typename TInputImageG::PixelType, +typename TInputImageNIR::PixelType, +typename TOutputImage::PixelType > > +class ITK_EXPORT RAndGAndNIRVegetationIndexImageFilter : public itk::TernaryFunctorImageFilter< TInputImageR, TInputImageG, TInputImageNIR, TOutputImage, TFunction > +{ +public: + + /** Standard typedefs */ + typedef RAndGAndNIRVegetationIndexImageFilter Self; + typedef itk::TernaryFunctorImageFilter< TInputImageR, TInputImageG, TInputImageNIR, TOutputImage, TFunction > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(RAndGAndNIRVegetationIndexImageFilter,TernaryFunctorImageFilter); + + void SetInputR( const TInputImageR * image ); + void SetInputG( const TInputImageG * image ); + void SetInputNIR( const TInputImageNIR * image ); + + /** Template parameters typedefs */ + typedef typename Superclass::Input1ImageType RInputImageType; + typedef typename Superclass::Input2ImageType GInputImageType; + typedef typename Superclass::Input3ImageType NIRInputImageType; + typedef typename Superclass::OutputImageType OutputImageType; + typedef typename Superclass::FunctorType FunctorType; + +protected: + RAndGAndNIRVegetationIndexImageFilter(); + virtual ~RAndGAndNIRVegetationIndexImageFilter() {}; + + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + RAndGAndNIRVegetationIndexImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbRAndGAndNIRVegetationIndexImageFilter.txx" +#endif + + +#endif diff --git a/Code/Radiometry/otbVegetationIndex.h b/Code/Radiometry/otbVegetationIndex.h index b2c554b848..7cd9d56467 100644 --- a/Code/Radiometry/otbVegetationIndex.h +++ b/Code/Radiometry/otbVegetationIndex.h @@ -94,7 +94,7 @@ private: * the Evaluate() method. */ template<class TInput1, class TInput2, class TInput3, class TOutput> -class RBAndNIRIndexBase +class RAndBAndNIRIndexBase { public: /// Vector pixel type used to support both vector images and multiple @@ -113,9 +113,9 @@ public: return this->Evaluate(r,b,nir); }; /// Constructor - RBAndNIRIndexBase() : m_RedIndex(3), m_BlueIndex(1), m_NIRIndex(4) {}; + RAndBAndNIRIndexBase() : m_RedIndex(3), m_BlueIndex(1), m_NIRIndex(4) {}; /// Desctructor - ~RBAndNIRIndexBase() {}; + ~RAndBAndNIRIndexBase() {}; /// Set Red Index void SetRedIndex(unsigned int channel) @@ -159,6 +159,79 @@ private: unsigned int m_NIRIndex; }; +/** base class for R, G And NIR based Index +* Implement operators for UnaryFunctorImageFilter templated with a +* VectorImage and BinaryFunctorImageFilter templated with single +* images. +* Subclasses should NOT overload operators, they must re-implement +* the Evaluate() method. +*/ +template<class TInput1, class TInput2, class TInput3, class TOutput> +class RAndGAndNIRIndexBase +{ +public: + /// Vector pixel type used to support both vector images and multiple + /// input images + typedef itk::VariableLengthVector<TInput1> InputVectorType; + + // Operator on vector pixel type + inline TOutput operator()(const InputVectorType & inputVector) + { + return this->Evaluate(inputVector[m_RedIndex-1],static_cast<TInput2>(inputVector[m_GreenIndex-1]), static_cast<TInput3>(inputVector[m_NIRIndex-1])); + } + + // Binary operator + inline TOutput operator()(const TInput1 &r, const TInput2 &g, const TInput2 &nir) + { + return this->Evaluate(r,g,nir); + }; + /// Constructor + RAndGAndNIRIndexBase() : m_RedIndex(3), m_GreenIndex(2), m_NIRIndex(4) {}; + /// Desctructor + ~RAndGAndNIRIndexBase() {}; + + /// Set Red Index + void SetRedIndex(unsigned int channel) + { + m_RedIndex = channel; + } + /// Get Red Index + unsigned int GetRedIndex() + { + return m_RedIndex; + } + /// Set Green Index + void SetGreenIndex(unsigned int channel) + { + m_GreenIndex = channel; + } + /// Get Green Index + unsigned int GetGreenIndex() + { + return m_GreenIndex; + } + + /// Set NIR Index + void SetNIRIndex(unsigned int channel) + { + m_NIRIndex = channel; + } + /// Get NIR Index + unsigned int GetNIRIndex() + { + return m_NIRIndex; + } +protected: + // This method must be reimplemented in subclasses to actually + // compute the index value + virtual TOutput Evaluate(const TInput1 & r, const TInput2& g, const TInput3 & nir) const = 0; + +private: + unsigned int m_RedIndex; + unsigned int m_GreenIndex; + unsigned int m_NIRIndex; +}; + /** \class NDVI @@ -402,6 +475,154 @@ protected: }; +/** \class GEMI + * \brief This functor calculate the Global Environment Monitoring Index (GEMI) + * + * [Pinty & Verstraete , 1992] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TOutput> +class GEMI : public RAndNIRIndexBase<TInput1, TInput2, TOutput> +{ +public: + GEMI() {}; + ~GEMI() {}; + +protected: + inline TOutput Evaluate(const TInput1 &r, const TInput2 &nir) const + { + double dnir = static_cast<double>(nir); + double dr = static_cast<double>(r); + + double dnu; + double dnumerateur_nu; + double ddenominateur_nu = dnir + dr + 0.5; + if ( ddenominateur_nu == 0 ) + { + dnu = 0; + } + else + { + dnumerateur_nu = 2*(dnir*dnir - dr*dr) + 1.5*dnir + 0.5*dr; + dnu = dnumerateur_nu / ddenominateur_nu; + } + + double ddenominateur_GEMI = 1 - dr; + if ( ddenominateur_GEMI == 0. ) + { + return static_cast<TOutput>(0.); + } + return ( static_cast<TOutput>( (dnu*(1 -0.25*dnu)-(dr-0.125))/ddenominateur_GEMI ) ); + } + +}; + +/** \class WDVI + * \brief This functor calculate the Weighted Difference Vegetation Index (WDVI) + * + * [Clevers, 1988] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TOutput> +class WDVI : public RAndNIRIndexBase<TInput1,TInput2,TOutput> +{ +public: + /// Constructor + WDVI() {}; + /// Desctructor + ~WDVI() {}; + // Operator on r and nir single pixel values +/** Set/Get Slop of soil line */ + void SetG(const double g) + { + m_G = g; + } + double GetG(void)const + { + return (m_G); + } +protected: + inline TOutput Evaluate(const TInput1 &r, const TInput2 &nir) const + { + double dr = static_cast<double>(r); + double dnir = static_cast<double>(nir); + return (dnir -m_G*dr); + } +private: + /** Slope of soil line */ + double m_G; +}; + +/** \class AVI + * \brief This functor calculate the Angular Vegetation Index (AVI) + * + * This vegetation index use three inputs channels + * + * [Plummer & al., 1994] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TInput3, class TOutput> +class AVI : public RAndGAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> +{ +public: + AVI() : m_LambdaR(660.), m_LambdaG(560.), m_LambdaNir(830.) {}; + ~AVI() {}; +/** Set/Get Lambda red parameter*/ + void SetLambdaR(const double lr) + { + m_LambdaR = lr; + } + double GetLambdaR(void)const + { + return (m_LambdaR); + } +/** Set/Get Lambda green parameter */ + void SetLambdaG(const double lg) + { + m_LambdaG = lg; + } + double GetLambdaG(void)const + { + return (m_LambdaG); + } +/** Set/Get Lambda red parameter */ + void SetLambdaNir(const double lnir) + { + m_LambdaNir = lnir; + } + double GetLambdaNir(void)const + { + return (m_LambdaNir); + } +protected: + inline TOutput Evaluate(const TInput1 &r, const TInput2 &g, const TInput3 &nir) const + { + double dr = static_cast<double>(r); + double dg = static_cast<double>(g); + double dnir = static_cast<double>(nir); + + double dfact1 = (m_LambdaNir - m_LambdaR) / m_LambdaR; + double dfact2 = (m_LambdaR - m_LambdaG) / m_LambdaR; + double dAVI = vcl_atan(dfact1/(dnir - dr)) + vcl_atan(dfact2/(dg - dr)); + + return ( static_cast<TOutput>( dAVI )); + } +private: + + /** Central wavelength of the red channel (=Lambda2) */ + double m_LambdaR; + + /** Central wavelength of the green channel (=Lambda1) */ + double m_LambdaG; + + /** Central wavelength of the nir channel (=Lambda3) */ + double m_LambdaNir; +}; + + /** \class ARVI * \brief This functor calculate the Atmospherically Resistant Vegetation Index (ARVI) * @@ -412,7 +633,7 @@ protected: * \ingroup Functor */ template <class TInput1, class TInput2, class TInput3, class TOutput> -class ARVI : public RBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> +class ARVI : public RAndBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> { public: ARVI() : m_Gamma(0.5) {}; @@ -457,7 +678,7 @@ private: * \ingroup Functor */ template <class TInput1, class TInput2, class TInput3, class TOutput> -class TSARVI: public RBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> +class TSARVI: public RAndBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> { public: TSARVI() : m_X(0.08), m_Gamma(0.5) {}; @@ -537,7 +758,7 @@ private: * \ingroup Functor */ template <class TInput1, class TInput2, class TInput3, class TOutput> -class EVI : public RBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> +class EVI : public RAndBAndNIRIndexBase<TInput1,TInput2,TInput3,TOutput> { public: EVI() : m_G(2.5), m_C1(6.0), m_C2(7.5), m_L(1.0) {}; @@ -607,6 +828,52 @@ private: double m_L; }; +/** \class IPVI + * \brief This functor calculate the + * + * [Qi et al., 1994] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TOutput> +class IPVI : public RAndNIRIndexBase<TInput1, TInput2, TOutput> +{ +public: + IPVI() {}; + ~IPVI() {}; + +protected: + inline TOutput Evaluate(const TInput1 &r, const TInput2 &nir) const + { + + return 0; + } + +}; + +/** \class TNDVI + * \brief This functor calculate the + * + * [Qi et al., 1994] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TOutput> +class TNDVI : public RAndNIRIndexBase<TInput1, TInput2, TOutput> +{ +public: + TNDVI() {}; + ~TNDVI() {}; + +protected: + inline TOutput Evaluate(const TInput1 &r, const TInput2 &nir) const + { + + return 0; + } + +}; + } // namespace Functor } // namespace otb diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index 82d1ff611b..aa698653a4 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -15,6 +15,7 @@ SET(RADIOMETRY_TESTS1 ${CXX_TEST_PATH}/otbRadiometryTests1) SET(RADIOMETRY_TESTS2 ${CXX_TEST_PATH}/otbRadiometryTests2) SET(RADIOMETRY_TESTS3 ${CXX_TEST_PATH}/otbRadiometryTests3) SET(RADIOMETRY_TESTS4 ${CXX_TEST_PATH}/otbRadiometryTests4) +SET(RADIOMETRY_TESTS5 ${CXX_TEST_PATH}/otbRadiometryTests5) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbRADIOMETRY_TESTS1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -509,7 +510,7 @@ ADD_TEST(raTvEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_T ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter EVI - ${INPUTDATA}/qb_RoadExtract.img.hdr + ${INPUTDATA}/qb_RoadExtract2sub200x200.tif ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif 3 # red 1 # blue @@ -540,7 +541,7 @@ ADD_TEST(raTvTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETR --compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_TSARVI_qb_RoadExtract.tif ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_qb_RoadExtract.tif otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter - ${INPUTDATA}/qb_RoadExtract.img.hdr + ${INPUTDATA}/qb_RoadExtract2sub200x200.tif ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_qb_RoadExtract.tif 3 # red 1 # blue @@ -551,8 +552,137 @@ ADD_TEST(raTvTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETR 0.5 # gamma ) +# ------- GEMI RAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTvGEMIRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} + --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_GEMI_poupees_subc1c2c3.tif + ${TEMP}/raRAndNIRVegetationIndex_GEMI_poupees_subc1c2c3.tif + otbRAndNIRVegetationIndexImageFilter + GEMI + ${INPUTDATA}/poupees_sub_c1.png + ${INPUTDATA}/poupees_sub_c2.png + ${TEMP}/raRAndNIRVegetationIndex_GEMI_poupees_subc1c2c3.tif +) + +# ------- GEMI MultiChannelRAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTvGEMIMultiChannelRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} + --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_GEMI_qb_RoadExtract.tif + ${TEMP}/raRAndNIRVegetationIndex_GEMI_qb_RoadExtract.tif + otbMultiChannelRAndNIRVegetationIndexImageFilter + GEMI + ${INPUTDATA}/qb_RoadExtract.img + ${TEMP}/raRAndNIRVegetationIndex_GEMI_qb_RoadExtract.tif + 3 4 # red nir +) + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbRADIOMETRY_TESTS5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ------- otb::RAndGAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTuRAndGAndNIRVegetationIndexImageFilterNew ${RADIOMETRY_TESTS5} + otbRAndGAndNIRVegetationIndexImageFilterNew ) + +# ------- otb::MultiChannelRAndGAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTuMultiChannelRAndGAndNIRVegetationIndexImageFilterNew ${RADIOMETRY_TESTS5} + otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew ) + +# ------- AVI RAndGAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvAVIRAndGAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndGAndNIRVegetationIndex_AVI_poupees_subc1c2c3.tif +# ${TEMP}/raRAndGAndNIRVegetationIndex_AVI_poupees_subc1c2c3.tif +# otbAVIRAndGAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/poupees_sub_c1.png +# ${INPUTDATA}/poupees_sub_c2.png +# ${INPUTDATA}/poupees_sub_c3.png +# ${TEMP}/raRAndGAndNIRVegetationIndex_AVI_poupees_subc1c2c3.tif +# 0.7 # lambda1 +# 0.9 # lambda2 +# 0.8 # lambda3 +# ) +# +# # ------- AVI MultiChannelRAndGAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndGAndNIRVegetationIndex_AVI_qb_RoadExtract.tif +# ${TEMP}/raRAndGAndNIRVegetationIndex_AVI_qb_RoadExtract.tif +# otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/qb_RoadExtract2sub200x200.tif +# ${TEMP}/raRAndGAndNIRVegetationIndex_AVI_qb_RoadExtract.tif +# 3 # red +# 2 # green +# 4 # nir +# 0.7 # lambda1 +# 0.9 # lambda2 +# 0.8 # lambda3 +# ) +# +# # ------- WDVI RAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvWDVIRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_WDVI_poupees_subc1c2c3.tif +# ${TEMP}/raRAndNIRVegetationIndex_WDVI_poupees_subc1c2c3.tif +# otbWDVIRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/poupees_sub_c1.png +# ${INPUTDATA}/poupees_sub_c2.png +# ${TEMP}/raRAndNIRVegetationIndex_WDVI_poupees_subc1c2c3.tif +# 1.0 # g : slope of soil line +# ) +# +# # ------- WDVI MultiChannelRAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvWDVIMultiChannelRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_WDVI_qb_RoadExtract.tif +# ${TEMP}/raRAndNIRVegetationIndex_WDVI_qb_RoadExtract.tif +# otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/qb_RoadExtract2sub200x200.tif +# ${TEMP}/raRAndNIRVegetationIndex_WDVI_qb_RoadExtract.tif +# 3 # red +# 4 # nir +# 1.0 # g : slope of soil line +# ) +# +# # ------- IPVI RAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvIPVIRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_IPVI_poupees_subc1c2c3.tif +# ${TEMP}/raRAndNIRVegetationIndex_IPVI_poupees_subc1c2c3.tif +# otbRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/poupees_sub_c1.png +# ${INPUTDATA}/poupees_sub_c2.png +# ${TEMP}/raRAndNIRVegetationIndex_IPVI_poupees_subc1c2c3.tif +# ) +# +# # ------- IPVI MultiChannelRAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvIPVIMultiChannelRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_IPVI_qb_RoadExtract.tif +# ${TEMP}/raRAndNIRVegetationIndex_IPVI_qb_RoadExtract.tif +# otbMultiChannelRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/qb_RoadExtract2sub200x200.tif +# ${TEMP}/raRAndNIRVegetationIndex_IPVI_qb_RoadExtract.tif +# 3 # red +# 1 # blue +# 4 # nir +# ) +# +# # ------- TNDVI RAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvTNDVIRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_TNDVI_poupees_subc1c2c3.tif +# ${TEMP}/raRAndNIRVegetationIndex_TNDVI_poupees_subc1c2c3.tif +# otbRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/poupees_sub_c1.png +# ${INPUTDATA}/poupees_sub_c2.png +# ${TEMP}/raRAndNIRVegetationIndex_TNDVI_poupees_subc1c2c3.tif +# ) +# +# # ------- TNDVI MultiChannelRAndNIRVegetationIndexImageFilter ------------------------------ +# ADD_TEST(raTvTNDVIMultiChannelRAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS5} +# --compare-image ${EPSILON} ${BASELINE}/raRAndNIRVegetationIndex_TNDVI_qb_RoadExtract.tif +# ${TEMP}/raRAndNIRVegetationIndex_TNDVI_qb_RoadExtract.tif +# otbMultiChannelRAndNIRVegetationIndexImageFilter +# ${INPUTDATA}/qb_RoadExtract2sub200x200.tif +# ${TEMP}/raRAndNIRVegetationIndex_TNDVI_qb_RoadExtract.tif +# 3 # red +# 1 # blue +# 4 # nir +# ) + # A enrichir SET(Radiometry_SRCS1 @@ -596,8 +726,26 @@ otbEVIRAndBAndNIRVegetationIndexImageFilter.cxx otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx + +# je remets ça ? DUPLICATION pas bon +otbRAndNIRVegetationIndexImageFilter.cxx +otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx +) +SET(Radiometry_SRCS5 +otbRAndGAndNIRVegetationIndexImageFilterNew.cxx +otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew.cxx +otbAVIRAndGAndNIRVegetationIndexImageFilter.cxx +otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx +otbWDVIRAndNIRVegetationIndexImageFilter.cxx +otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter.cxx + + +# je remets ça ? DUPLICATION pas bon +otbRAndNIRVegetationIndexImageFilter.cxx +otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx ) + INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") ADD_EXECUTABLE(otbRadiometryTests1 otbRadiometryTests1.cxx ${Radiometry_SRCS1}) @@ -608,5 +756,7 @@ ADD_EXECUTABLE(otbRadiometryTests3 otbRadiometryTests3.cxx ${Radiometry_SRCS3}) TARGET_LINK_LIBRARIES(otbRadiometryTests3 OTBRadiometry OTBIO) ADD_EXECUTABLE(otbRadiometryTests4 otbRadiometryTests4.cxx ${Radiometry_SRCS4}) TARGET_LINK_LIBRARIES(otbRadiometryTests4 OTBRadiometry OTBIO) +ADD_EXECUTABLE(otbRadiometryTests5 otbRadiometryTests5.cxx ${Radiometry_SRCS5}) +TARGET_LINK_LIBRARIES(otbRadiometryTests5 OTBRadiometry OTBIO) ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) diff --git a/Testing/Code/Radiometry/otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..b7e5127dc7 --- /dev/null +++ b/Testing/Code/Radiometry/otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,77 @@ +/*========================================================================= + + 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 "otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef otb::VectorImage<double ,Dimension> InputImageType; + typedef otb::Image<double,Dimension> OutputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef otb::Functor::AVI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType > FunctorType; + typedef otb::MultiChannelRAndGAndNIRVegetationIndexImageFilter<InputImageType,OutputImageType,FunctorType> + MultiChannelRAndGAndNIRVegetationIndexImageFilterType; + + // Instantiating object + MultiChannelRAndGAndNIRVegetationIndexImageFilterType::Pointer filter = MultiChannelRAndGAndNIRVegetationIndexImageFilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + const char * inputFilename = argv[1]; + const char * outputFilename = argv[2]; + + unsigned int redChannel(::atoi(argv[3])); + unsigned int greenChannel(::atoi(argv[4])); + unsigned int nirChannel(::atoi(argv[5])); + + double lg(::atof(argv[6])); + double lr(::atof(argv[7])); + double lnir(::atof(argv[8])); + + reader->SetFileName( inputFilename ); + writer->SetFileName( outputFilename ); + filter->SetRedIndex(redChannel); + filter->SetGreenIndex(greenChannel); + filter->SetNIRIndex(nirChannel); + filter->SetInput( reader->GetOutput() ); + + filter->GetFunctor().SetLambdaG(lg); + filter->GetFunctor().SetLambdaR(lr); + filter->GetFunctor().SetLambdaNir(lnir); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + return EXIT_SUCCESS; +} + + + + diff --git a/Testing/Code/Radiometry/otbAVIRAndGAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbAVIRAndGAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..37b956d4ec --- /dev/null +++ b/Testing/Code/Radiometry/otbAVIRAndGAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,88 @@ +/*========================================================================= + + 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 "otbRAndGAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbAVIRAndGAndNIRVegetationIndexImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::Image<PixelType,Dimension> InputRImageType; + typedef otb::Image<PixelType,Dimension> InputGImageType; + typedef otb::Image<PixelType,Dimension> InputNIRImageType; + typedef otb::Image<double,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputRImageType> RReaderType; + typedef otb::ImageFileReader<InputGImageType> GReaderType; + typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + typedef otb::Functor::AVI< InputRImageType::PixelType, + InputGImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType > FunctorType; + + typedef otb::RAndGAndNIRVegetationIndexImageFilter< InputRImageType, + InputGImageType, + InputNIRImageType, + OutputImageType, + FunctorType > RAndGAndNIRVegetationIndexImageFilterType; + + // Instantiating object + RAndGAndNIRVegetationIndexImageFilterType::Pointer filter = RAndGAndNIRVegetationIndexImageFilterType::New(); + RReaderType::Pointer readerR = RReaderType::New(); + GReaderType::Pointer readerG = GReaderType::New(); + NIRReaderType::Pointer readerNIR = NIRReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + + const char * inputFilenameR = argv[1]; + const char * inputFilenameG = argv[2]; + const char * inputFilenameNIR = argv[3]; + const char * outputFilename = argv[4]; + + double lg(::atof(argv[5])); + double lr(::atof(argv[6])); + double lnir(::atof(argv[7])); + + + readerR->SetFileName( inputFilenameR ); + readerG->SetFileName( inputFilenameG ); + readerNIR->SetFileName( inputFilenameNIR ); + writer->SetFileName( outputFilename ); + filter->SetInputR( readerR->GetOutput() ); + filter->SetInputG( readerG->GetOutput() ); + filter->SetInputNIR( readerNIR->GetOutput() ); + + filter->GetFunctor().SetLambdaG(lg); + filter->GetFunctor().SetLambdaR(lr); + filter->GetFunctor().SetLambdaNir(lnir); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew.cxx b/Testing/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew.cxx new file mode 100644 index 0000000000..496a54302f --- /dev/null +++ b/Testing/Code/Radiometry/otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew.cxx @@ -0,0 +1,37 @@ +/*========================================================================= + + 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 "otbMultiChannelRAndGAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbVectorImage.h" + + +int otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef otb::VectorImage<unsigned char,Dimension> InputImageType; + typedef otb::Image<float,Dimension> OutputImageType; + typedef otb::MultiChannelRAndGAndNIRVegetationIndexImageFilter<InputImageType,OutputImageType> MultiChannelRAndGAndNIRVegetationIndexImageFilterType; + + // Instantiating object + MultiChannelRAndGAndNIRVegetationIndexImageFilterType::Pointer object = MultiChannelRAndGAndNIRVegetationIndexImageFilterType::New(); + + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Radiometry/otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx index 33305b94fd..7491a5acbb 100644 --- a/Testing/Code/Radiometry/otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx +++ b/Testing/Code/Radiometry/otbMultiChannelRAndNIRVegetationIndexImageFilter.cxx @@ -93,6 +93,21 @@ int otbMultiChannelRAndNIRVegetationIndexImageFilter(int argc, char * argv[]) InputImageType::InternalPixelType, OutputImageType::PixelType> > (argc,argv) ); + else if ( strArgv == "GEMI" ) return( generic_MultiChannelRAndNIRVegetationIndexImageFilter<InputImageType, OutputImageType, + otb::Functor::GEMI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType> > + (argc,argv) ); + else if ( strArgv == "IPVI" ) return( generic_MultiChannelRAndNIRVegetationIndexImageFilter<InputImageType, OutputImageType, + otb::Functor::IPVI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType> > + (argc,argv) ); + else if ( strArgv == "TNDVI" ) return( generic_MultiChannelRAndNIRVegetationIndexImageFilter<InputImageType, OutputImageType, + otb::Functor::IPVI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType> > + (argc,argv) ); else return EXIT_FAILURE; return EXIT_SUCCESS; diff --git a/Testing/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilterNew.cxx b/Testing/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilterNew.cxx new file mode 100644 index 0000000000..d477833258 --- /dev/null +++ b/Testing/Code/Radiometry/otbRAndGAndNIRVegetationIndexImageFilterNew.cxx @@ -0,0 +1,43 @@ +/*========================================================================= + + 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 "itkExceptionObject.h" + +#include "otbRAndGAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" + +int otbRAndGAndNIRVegetationIndexImageFilterNew(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef unsigned char PixelType; + typedef otb::Image<PixelType,Dimension> InputRImageType; + typedef otb::Image<PixelType,Dimension> InputGImageType; + typedef otb::Image<PixelType,Dimension> InputNIRImageType; + typedef otb::Image<PixelType,Dimension> OutputImageType; + + typedef otb::RAndGAndNIRVegetationIndexImageFilter<InputRImageType,InputGImageType,InputNIRImageType,OutputImageType> RAndGAndNIRVegetationIndexImageFilterType; + + // Instantiating object + RAndGAndNIRVegetationIndexImageFilterType::Pointer object = RAndGAndNIRVegetationIndexImageFilterType::New(); + + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Radiometry/otbRAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbRAndNIRVegetationIndexImageFilter.cxx index c278223f3e..f4d17cacf7 100644 --- a/Testing/Code/Radiometry/otbRAndNIRVegetationIndexImageFilter.cxx +++ b/Testing/Code/Radiometry/otbRAndNIRVegetationIndexImageFilter.cxx @@ -97,6 +97,21 @@ int otbRAndNIRVegetationIndexImageFilter(int argc, char * argv[]) InputNIRImageType::PixelType, OutputImageType::PixelType> > (argc,argv) ); + else if ( strArgv == "GEMI" ) return( generic_RAndNIRVegetationIndexImageFilter<InputRImageType, InputNIRImageType, OutputImageType, + otb::Functor::GEMI< InputRImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType> > + (argc,argv) ); + else if ( strArgv == "IPVI" ) return( generic_RAndNIRVegetationIndexImageFilter<InputRImageType, InputNIRImageType, OutputImageType, + otb::Functor::IPVI< InputRImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType> > + (argc,argv) ); + else if ( strArgv == "TNDVI" ) return( generic_RAndNIRVegetationIndexImageFilter<InputRImageType, InputNIRImageType, OutputImageType, + otb::Functor::TNDVI< InputRImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType> > + (argc,argv) ); else return EXIT_FAILURE; return EXIT_SUCCESS; diff --git a/Testing/Code/Radiometry/otbRadiometryTests4.cxx b/Testing/Code/Radiometry/otbRadiometryTests4.cxx index 406d589c40..8b5c0624f7 100644 --- a/Testing/Code/Radiometry/otbRadiometryTests4.cxx +++ b/Testing/Code/Radiometry/otbRadiometryTests4.cxx @@ -34,5 +34,9 @@ void RegisterTests() REGISTER_TEST(otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter); REGISTER_TEST(otbTSARVIRAndBAndNIRVegetationIndexImageFilter); REGISTER_TEST(otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter); + +/* A TRIER */ + REGISTER_TEST(otbRAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbMultiChannelRAndNIRVegetationIndexImageFilter); } diff --git a/Testing/Code/Radiometry/otbRadiometryTests5.cxx b/Testing/Code/Radiometry/otbRadiometryTests5.cxx new file mode 100644 index 0000000000..17e2d28002 --- /dev/null +++ b/Testing/Code/Radiometry/otbRadiometryTests5.cxx @@ -0,0 +1,37 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +// this file defines the otbCommonTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include <iostream> +#include "otbTestMain.h" + +void RegisterTests() +{ + REGISTER_TEST(otbRAndGAndNIRVegetationIndexImageFilterNew); + REGISTER_TEST(otbMultiChannelRAndGAndNIRVegetationIndexImageFilterNew); + REGISTER_TEST(otbAVIRAndGAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbAVIMultiChannelRAndGAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbWDVIRAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter); +} + diff --git a/Testing/Code/Radiometry/otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..a95366bdde --- /dev/null +++ b/Testing/Code/Radiometry/otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,70 @@ +/*========================================================================= + + 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 "otbMultiChannelRAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbWDVIMultiChannelRAndNIRVegetationIndexImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef otb::VectorImage<double ,Dimension> InputImageType; + typedef otb::Image<double,Dimension> OutputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef otb::Functor::WDVI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType > FunctorType; + typedef otb::MultiChannelRAndNIRVegetationIndexImageFilter<InputImageType,OutputImageType,FunctorType> + MultiChannelRAndNIRVegetationIndexImageFilterType; + + // Instantiating object + MultiChannelRAndNIRVegetationIndexImageFilterType::Pointer filter = MultiChannelRAndNIRVegetationIndexImageFilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + const char * inputFilename = argv[1]; + const char * outputFilename = argv[2]; + + unsigned int redChannel(::atoi(argv[3])); + unsigned int nirChannel(::atoi(argv[4])); + + double g(::atof(argv[5])); + + reader->SetFileName( inputFilename ); + writer->SetFileName( outputFilename ); + filter->SetRedIndex(redChannel); + filter->SetNIRIndex(nirChannel); + filter->SetInput( reader->GetOutput() ); + + filter->GetFunctor().SetG(g); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + return EXIT_SUCCESS; +} + + + + diff --git a/Testing/Code/Radiometry/otbWDVIRAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbWDVIRAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..6f148e38fb --- /dev/null +++ b/Testing/Code/Radiometry/otbWDVIRAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,75 @@ +/*========================================================================= + + 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 "otbRAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbWDVIRAndNIRVegetationIndexImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::Image<PixelType,Dimension> InputRImageType; + typedef otb::Image<PixelType,Dimension> InputNIRImageType; + typedef otb::Image<double,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputRImageType> RReaderType; + typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + typedef otb::Functor::WDVI< InputRImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType > FunctorType; + + typedef otb::RAndNIRVegetationIndexImageFilter< InputRImageType, + InputNIRImageType, + OutputImageType, + FunctorType > RAndNIRVegetationIndexImageFilterType; + + // Instantiating object + RAndNIRVegetationIndexImageFilterType::Pointer filter = RAndNIRVegetationIndexImageFilterType::New(); + RReaderType::Pointer readerR = RReaderType::New(); + NIRReaderType::Pointer readerNIR = NIRReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + + const char * inputFilenameR = argv[1]; + const char * inputFilenameNIR = argv[2]; + const char * outputFilename = argv[3]; + + double g(::atof(argv[4])); + + readerR->SetFileName( inputFilenameR ); + readerNIR->SetFileName( inputFilenameNIR ); + writer->SetFileName( outputFilename ); + filter->SetInputR( readerR->GetOutput() ); + filter->SetInputNIR( readerNIR->GetOutput() ); + + filter->GetFunctor().SetG(g); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + + return EXIT_SUCCESS; +} + -- GitLab