From 7b34d85cb9816c9022837f17c92c7712b9050a48 Mon Sep 17 00:00:00 2001 From: Guillaume Borrut <guillaume.borrut@c-s.fr> Date: Wed, 4 Feb 2009 17:49:41 +0100 Subject: [PATCH] ENH : Adding TSARVI Functor and associated testings --- Code/Radiometry/otbVegetationIndex.h | 79 +++++++++++++++- Testing/Code/Radiometry/CMakeLists.txt | 39 +++++++- ...lRAndBAndNIRVegetationIndexImageFilter.cxx | 1 - .../Code/Radiometry/otbRadiometryTests4.cxx | 2 + ...lRAndBAndNIRVegetationIndexImageFilter.cxx | 79 ++++++++++++++++ ...IRAndBAndNIRVegetationIndexImageFilter.cxx | 89 +++++++++++++++++++ 6 files changed, 284 insertions(+), 5 deletions(-) create mode 100644 Testing/Code/Radiometry/otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx create mode 100644 Testing/Code/Radiometry/otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx diff --git a/Code/Radiometry/otbVegetationIndex.h b/Code/Radiometry/otbVegetationIndex.h index ba2763e056..68d268a4a7 100644 --- a/Code/Radiometry/otbVegetationIndex.h +++ b/Code/Radiometry/otbVegetationIndex.h @@ -295,6 +295,84 @@ private: double m_Gamma; }; + + + +/** \class TSARVI + * \brief This functor calculate the Transformed Soil Atmospherical Resistant Vegetation Index (TSARVI) + * + * [Yoram J. Kaufman and Didier Tanré, 1992] + * + * \ingroup Functor + */ +template <class TInput1, class TInput2, class TInput3, class TOutput> +class TSARVI +{ +public: + TSARVI() : m_X(0.08), m_Gamma(0.5) {}; + ~TSARVI() {}; + inline TOutput operator()(const TInput1 &r, const TInput2 &b, const TInput3 &nir) + { + double dr = static_cast<double>(r); + double db = static_cast<double>(b); + double dnir = static_cast<double>(nir); + double dRB = dr - m_Gamma*(db - dr); + double denominator = dRB + m_A*dnir - m_A*m_B + m_X*(1.+m_A*m_A); + if ( denominator == 0. ) + { + return static_cast<TOutput>(0.); + } + return ( static_cast<TOutput>( (m_A*(dnir - m_A*dRB - m_B))/denominator ) ); + } + /** Set/Get A and B parameters */ + void SetA(const double A) + { + m_A = A; + } + double GetA(void)const + { + return (m_A); + } + void SetB(const double B) + { + m_B = B; + } + double GetB(void)const + { + return (m_B); + } + /** Set/Get X parameter */ + void SetX(const double X) + { + m_X = X; + } + double GetX(void)const + { + return (m_X); + } + /** Set/Get the gamma parameter */ + void SetGamma(const double gamma) + { + m_Gamma = gamma; + } + double GetGamma(void)const + { + return (m_Gamma); + } + +private: + + /** A and B parameters */ + double m_A; + double m_B; + /** X parameter */ + double m_X; + /** Gamma parameter */ + double m_Gamma; + +}; + + /** \class EVI * \brief This functor calculate the Enhanced Vegetation Index (EVI) * @@ -321,7 +399,6 @@ public: return static_cast<TOutput>(0.); } return ( static_cast<TOutput>( m_G * (dnir - dr)/denominator ) ); -//return ( static_cast<TOutput>( dnir ) ); } /** Set/Get G parameter */ void SetG(const double g) diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index c05f18b6ae..bdd13738ea 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -181,7 +181,7 @@ ADD_TEST(raTvARVI_MultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY ${INPUTDATA}/poupees_sub.png ${TEMP}/raMultiChannelRAndBAndNIRVegetationIndex_ARVI_poupees_subc1c2c3.tif 1 2 3 - 0.6 # Gamma parameter + 0.6 # Gamma parameter ) # ------- otb::ImageToLuminanceImageFilter ------------------------------ @@ -487,7 +487,7 @@ ADD_TEST(raTvAtmosphericCorrectionSequencementTest ${RADIOMETRY_TESTS4} ) -# ------- otb::RAndBAndNIRVegetationIndexImageFilter ------------------------------ +# ------- EVI RAndBAndNIRVegetationIndexImageFilter ------------------------------ ADD_TEST(raTvEVIRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} --compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_EVI_poupees_subc1c2c3.tif ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_poupees_subc1c2c3.tif @@ -503,7 +503,7 @@ ADD_TEST(raTvEVIRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} 1.0 ) -# ------- otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter ------------------------------ +# ------- EVI MultiChannelRAndBAndNIRVegetationIndexImageFilter ------------------------------ ADD_TEST(raTvEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} --compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif @@ -520,6 +520,37 @@ ADD_TEST(raTvEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_T 400.0 # canopy background adjustment ) +# ------- TSARVI RAndBAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTvTSARVIRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} + --compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_TSARVI_poupees_subc1c2c3.tif + ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_poupees_subc1c2c3.tif + otbTSARVIRAndBAndNIRVegetationIndexImageFilter + ${INPUTDATA}/poupees_sub_c1.png + ${INPUTDATA}/poupees_sub_c2.png + ${INPUTDATA}/poupees_sub_c3.png + ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_poupees_subc1c2c3.tif + 0.7 # a ( pente de la droite des sols nus dans l'espace RB/PIR ) + 0.9 # b ( ordonnée à l'origine de la droite des sols nus dans l'espace RB/PIR ) + 0.08 # x coeff a priori constant + 0.5 # gamma +) + +# ------- TSARVI MultiChannelRAndBAndNIRVegetationIndexImageFilter ------------------------------ +ADD_TEST(raTvTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} + --compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif + ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_qb_RoadExtract.tif + otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter + ${INPUTDATA}/qb_RoadExtract.img.hdr + ${TEMP}/raRAndBAndNIRVegetationIndex_TSARVI_qb_RoadExtract.tif + 3 # red + 1 # blue + 4 # nir + 0.7 # a ( pente de la droite des sols nus dans l'espace RB/PIR ) + 0.9 # b ( ordonnée à l'origine de la droite des sols nus dans l'espace RB/PIR ) + 0.08 # x coeff a priori constant + 0.5 # gamma +) + @@ -563,6 +594,8 @@ otbAtmosphericCorrectionParametersTo6SAtmosphericRadiativeTerms.cxx otbAtmosphericCorrectionSequencement.cxx otbEVIRAndBAndNIRVegetationIndexImageFilter.cxx otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx +otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index c8d18acff4..bd3d6503c4 100644 --- a/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -45,7 +45,6 @@ int generic_EVIMultiChannelRAndBAndNIRVegetationIndexImageFilter(int argc, char unsigned int redChannel(::atoi(argv[3])); unsigned int blueChannel(::atoi(argv[4])); unsigned int nirChannel(::atoi(argv[5])); -std::cout << "ORDER : "<<redChannel<<" "<<blueChannel<<" "<<nirChannel<<std::endl; double g(::atof(argv[6])); double c1(::atof(argv[7])); diff --git a/Testing/Code/Radiometry/otbRadiometryTests4.cxx b/Testing/Code/Radiometry/otbRadiometryTests4.cxx index c51fb1b5a2..406d589c40 100644 --- a/Testing/Code/Radiometry/otbRadiometryTests4.cxx +++ b/Testing/Code/Radiometry/otbRadiometryTests4.cxx @@ -32,5 +32,7 @@ void RegisterTests() REGISTER_TEST(otbAtmosphericCorrectionSequencementTest); REGISTER_TEST(otbEVIRAndBAndNIRVegetationIndexImageFilter); REGISTER_TEST(otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbTSARVIRAndBAndNIRVegetationIndexImageFilter); + REGISTER_TEST(otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter); } diff --git a/Testing/Code/Radiometry/otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..7785d4f838 --- /dev/null +++ b/Testing/Code/Radiometry/otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,79 @@ +/*========================================================================= + + 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 "otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbTSARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter(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::TSARVI< InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + InputImageType::InternalPixelType, + OutputImageType::PixelType > FunctorType; + typedef otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter<InputImageType,OutputImageType,FunctorType> + MultiChannelRAndBAndNIRVegetationIndexImageFilterType; + + // Instantiating object + MultiChannelRAndBAndNIRVegetationIndexImageFilterType::Pointer filter = MultiChannelRAndBAndNIRVegetationIndexImageFilterType::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 blueChannel(::atoi(argv[4])); + unsigned int nirChannel(::atoi(argv[5])); + + double a(::atof(argv[6])); + double b(::atof(argv[7])); + double x(::atof(argv[8])); + double gamma(::atof(argv[9])); + + reader->SetFileName( inputFilename ); + writer->SetFileName( outputFilename ); + filter->SetRedIndex(redChannel); + filter->SetBlueIndex(blueChannel); + filter->SetNIRIndex(nirChannel); + filter->SetInput( reader->GetOutput() ); + + filter->GetFunctor().SetA(a); + filter->GetFunctor().SetB(b); + filter->GetFunctor().SetX(x); + filter->GetFunctor().SetGamma(gamma); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + return EXIT_SUCCESS; +} + + + + diff --git a/Testing/Code/Radiometry/otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx new file mode 100644 index 0000000000..66badd3a88 --- /dev/null +++ b/Testing/Code/Radiometry/otbTSARVIRAndBAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,89 @@ +/*========================================================================= + + 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 "otbRAndBAndNIRVegetationIndexImageFilter.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVegetationIndex.h" + + +int otbTSARVIRAndBAndNIRVegetationIndexImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::Image<PixelType,Dimension> InputRImageType; + typedef otb::Image<PixelType,Dimension> InputBImageType; + typedef otb::Image<PixelType,Dimension> InputNIRImageType; + typedef otb::Image<double,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputRImageType> RReaderType; + typedef otb::ImageFileReader<InputBImageType> BReaderType; + typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + typedef otb::Functor::TSARVI< InputRImageType::PixelType, + InputBImageType::PixelType, + InputNIRImageType::PixelType, + OutputImageType::PixelType > FunctorType; + + typedef otb::RAndBAndNIRVegetationIndexImageFilter< InputRImageType, + InputBImageType, + InputNIRImageType, + OutputImageType, + FunctorType > RAndBAndNIRVegetationIndexImageFilterType; + + // Instantiating object + RAndBAndNIRVegetationIndexImageFilterType::Pointer filter = RAndBAndNIRVegetationIndexImageFilterType::New(); + RReaderType::Pointer readerR = RReaderType::New(); + BReaderType::Pointer readerB = BReaderType::New(); + NIRReaderType::Pointer readerNIR = NIRReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + + const char * inputFilenameR = argv[1]; + const char * inputFilenameB = argv[2]; + const char * inputFilenameNIR = argv[3]; + const char * outputFilename = argv[4]; + + double a(::atof(argv[5])); + double b(::atof(argv[6])); + double x(::atof(argv[7])); + double gamma(::atof(argv[8])); + + readerR->SetFileName( inputFilenameR ); + readerB->SetFileName( inputFilenameB ); + readerNIR->SetFileName( inputFilenameNIR ); + writer->SetFileName( outputFilename ); + filter->SetInputR( readerR->GetOutput() ); + filter->SetInputB( readerB->GetOutput() ); + filter->SetInputNIR( readerNIR->GetOutput() ); + + filter->GetFunctor().SetA(a); + filter->GetFunctor().SetB(b); + filter->GetFunctor().SetX(x); + filter->GetFunctor().SetGamma(gamma); + + writer->SetInput( filter->GetOutput() ); + writer->Update(); + + + return EXIT_SUCCESS; +} + -- GitLab