From c4be05b915bc68ce3089a48b11c621d6699cb749 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Mon, 15 Apr 2019 15:36:37 +0000 Subject: [PATCH] TEST: Fix failing tests and fix band index convention (always start at 1) --- .../ARVIMultiChannelRAndBAndNIRVegetationIndex.tif | 4 ++-- ...iChannelRAndBAndNIRVegetationIndexImageFilter.cxx | 2 +- .../AppIndices/app/otbRadiometricIndices.cxx | 11 ++++++++++- .../Indices/include/otbNDVIDataNodeFeatureFunction.h | 8 ++++---- .../Indices/include/otbRadiometricIndice.h | 8 ++++---- .../Indices/include/otbVegetationIndicesFunctor.h | 3 +-- .../Indices/test/otbRadiometricIndicesTest.cxx | 12 ++++++------ 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Data/Baseline/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif b/Data/Baseline/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif index 0225c9d196..4361cfbb8a 100644 --- a/Data/Baseline/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif +++ b/Data/Baseline/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:42df562a687bdf13d65cacc6da48666b28da72efa79d7d668e607cf82eba4c11 -size 68855 +oid sha256:91667b86ce412524444bde780eee2c7f0baff0c05ecdc5b66a49aca39bc60dda +size 65842 diff --git a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index 6fdd9cfce9..8f0f2d304f 100644 --- a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) // The three used index bands (red, blue and NIR) are declared. filter->GetFunctor().SetBandIndex(CommonBandNames::RED,::atoi(argv[5])); - filter->GetFunctor().SetBandIndex(CommonBandNames::GREEN,::atoi(argv[6])); + filter->GetFunctor().SetBandIndex(CommonBandNames::BLUE,::atoi(argv[6])); filter->GetFunctor().SetBandIndex(CommonBandNames::NIR,::atoi(argv[7])); // The filter input is linked to the reader output and diff --git a/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx b/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx index 67f911d2fb..535285cab4 100644 --- a/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx +++ b/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx @@ -94,18 +94,27 @@ private: AddParameter(ParameterType_Int, "channels.blue", "Blue Channel"); SetParameterDescription("channels.blue", "Blue channel index"); SetDefaultParameterInt("channels.blue", 1); + SetMinimumParameterIntValue("channels.blue",1); + AddParameter(ParameterType_Int, "channels.green", "Green Channel"); SetParameterDescription("channels.green", "Green channel index"); SetDefaultParameterInt("channels.green", 1); + SetMinimumParameterIntValue("channels.green",1); + AddParameter(ParameterType_Int, "channels.red", "Red Channel"); SetParameterDescription("channels.red", "Red channel index"); SetDefaultParameterInt("channels.red", 1); + SetMinimumParameterIntValue("channels.red",1); + AddParameter(ParameterType_Int, "channels.nir", "NIR Channel"); SetParameterDescription("channels.nir", "NIR channel index"); SetDefaultParameterInt("channels.nir", 1); + SetMinimumParameterIntValue("channels.nir",1); + AddParameter(ParameterType_Int, "channels.mir", "Mir Channel"); SetParameterDescription("channels.mir", "Mir channel index"); SetDefaultParameterInt("channels.mir", 1); + SetMinimumParameterIntValue("channels.mir",1); AddParameter(ParameterType_ListView, "list", "Available Radiometric Indices"); SetParameterDescription("list", @@ -212,7 +221,7 @@ private: } else { - indicesMap[band] = idx-1; + indicesMap[band] = idx; } } }; diff --git a/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h b/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h index 46e7d2c643..1097860300 100644 --- a/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h +++ b/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h @@ -97,22 +97,22 @@ public: //TODO replace by metadata parsing unsigned int GetREDChannelIndex() const { - return m_NDVIFunctor.GetBandIndex(CommonBandNames::RED)+1; + return m_NDVIFunctor.GetBandIndex(CommonBandNames::RED); } void SetREDChannelIndex(unsigned int id) { - m_NDVIFunctor.SetBandIndex(CommonBandNames::RED,id-1); + m_NDVIFunctor.SetBandIndex(CommonBandNames::RED,id); } unsigned int GetNIRChannelIndex() const { - return m_NDVIFunctor.GetBandIndex(CommonBandNames::NIR)+1; + return m_NDVIFunctor.GetBandIndex(CommonBandNames::NIR); } void SetNIRChannelIndex(unsigned int id) { - m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR,id-1); + m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR,id); } protected: diff --git a/Modules/Radiometry/Indices/include/otbRadiometricIndice.h b/Modules/Radiometry/Indices/include/otbRadiometricIndice.h index 28d8ce7fb9..dc45c9d0c8 100644 --- a/Modules/Radiometry/Indices/include/otbRadiometricIndice.h +++ b/Modules/Radiometry/Indices/include/otbRadiometricIndice.h @@ -117,7 +117,7 @@ public: /** * \param band The band to set (value in TBandNameEnum) - * \param index The index of the band to set + * \param index The index of the band to set (starts at 1 for first band) * \throw runtime_error if band is TBandNameEnum::MAX */ void SetBandIndex(const BandNameType & band, const size_t & index) @@ -131,7 +131,7 @@ public: /** * \param indicesMap a std::map<TBandNameEnum,size_t> containing all - * bands indices to set + * bands indices to set (starts at 1 for first band) * \throw runtime_error if indicesMap contains TBandNameEnum::MAX */ void SetBandsIndices(const std::map<BandNameType,size_t> & indicesMap) @@ -160,7 +160,7 @@ public: * Astract method which will compute the radiometric indice * \param input A itk::VariableLengthVector<TInput> holding the * pixel values for each band - * \return The indice value as TOutput + * \return The indice value as TOutput (starts at 1 for first band) */ virtual TOutput operator()(const itk::VariableLengthVector<TInput> & input) const = 0; @@ -201,7 +201,7 @@ protected: double Value(const BandNameType & band, const itk::VariableLengthVector<TInput> & input) const { assert(m_RequiredBands[band] && "Retrieving value for a band that is not in the required bands list"); - return static_cast<double>(input[UncheckedBandIndex(band)]); + return static_cast<double>(input[UncheckedBandIndex(band)-1]); } private: diff --git a/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h b/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h index 3e7fc70dde..860cf367a7 100644 --- a/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h +++ b/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h @@ -737,8 +737,7 @@ public: { return static_cast<TOutput>(0.); } - - return static_cast<TOutput>(A*((std::exp((nir-red)/((red+nir)*B))-std::exp(C*B)))); + return static_cast<TOutput>(A*(std::exp((nir-red)/(red+nir)*B)-std::exp(C*B))); } static constexpr double A = 0.1519; diff --git a/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx b/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx index 2b2a083f8e..853d372970 100644 --- a/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx +++ b/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx @@ -68,7 +68,7 @@ using namespace otb::Functor; int otbVegetationIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}}; + const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) bool res = CheckResult< NDVI<int,double> >("ndvi_null ",bandMap,{0,0,0,0},0.); @@ -90,7 +90,7 @@ int otbVegetationIndicesTest(int, char**) res = res & CheckResult< IPVI<int,double> >("ipvi_pixel",bandMap,{0,0,1,2},0.6666666667); res = res & CheckResult< LAIFromNDVILogarithmic<int,double> >("lailog_pixel",bandMap,{0,0,1,2},0.4930511672); res = res & CheckResult< LAIFromReflectancesLinear<int,double> >("lailog_pixel",bandMap,{0,0,1,2},6.61); - res = res & CheckResult< LAIFromNDVIFormosat2Functor<int,double> >("laifrom_pixel",bandMap,{0,0,1,2},-0.08836147592); + res = res & CheckResult< LAIFromNDVIFormosat2Functor<int,double> >("laifrom_pixel",bandMap,{0,0,1,2},0.3120010659); if(res) { @@ -104,7 +104,7 @@ int otbVegetationIndicesTest(int, char**) int otbWaterIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}}; + const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) bool res = CheckResult< NDWI<int,double> >("ndwi_null ",bandMap,{0,0,0,0,0},0.); @@ -128,7 +128,7 @@ int otbWaterIndicesTest(int, char**) int otbSoilIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}}; + const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) bool res = CheckResult< CI<int,double> >("ci_null ",bandMap,{0,0,0,0,0},0.); @@ -148,7 +148,7 @@ int otbSoilIndicesTest(int, char**) int otbBuiltUpIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}}; + const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) bool res = CheckResult< ISU<int,double> >("isu_null",bandMap,{0,0,0,0,0},0.); @@ -237,7 +237,7 @@ int otbIndicesStackFunctorTest(int, char**) success = false; } - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,0},{CommonBandNames::GREEN,1},{CommonBandNames::RED,2},{CommonBandNames::NIR,3}, {CommonBandNames::MIR,4}}; + const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; ndvi.SetBandsIndices(bandMap); ndwi.SetBandsIndices(bandMap); -- GitLab