diff --git a/Code/FeatureExtraction/otbEnergyTextureFunctor.h b/Code/FeatureExtraction/otbEnergyTextureFunctor.h index b6990c60f2fac34c642fba933a4955f97919d288..8d907fb25b500af523a6829c5027742fd33605a5 100644 --- a/Code/FeatureExtraction/otbEnergyTextureFunctor.h +++ b/Code/FeatureExtraction/otbEnergyTextureFunctor.h @@ -69,7 +69,6 @@ public: double temp = 0.; double norm = 0.; - double output = 0.; offsetOff = offsetOffInit; for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) diff --git a/Code/FeatureExtraction/otbEntropyTextureFunctor.h b/Code/FeatureExtraction/otbEntropyTextureFunctor.h index d0e1fc64cd0b872026aa98ff021a2f6e7a9496f5..b62561e730e791937c87bd698005c738d00bdb9b 100644 --- a/Code/FeatureExtraction/otbEntropyTextureFunctor.h +++ b/Code/FeatureExtraction/otbEntropyTextureFunctor.h @@ -41,13 +41,7 @@ class ITK_EXPORT EntropyTextureFunctor : public TextureFunctorBase<TIterInput1, TIterInput2, TOutput> { public: - EntropyTextureFunctor() - { - m_Mini = itk::NumericTraits<double>::max(); - m_MiniOff = itk::NumericTraits<double>::max(); - m_Maxi = itk::NumericTraits<double>::NonpositiveMin(); - m_MaxiOff = itk::NumericTraits<double>::NonpositiveMin(); - }; + EntropyTextureFunctor(){}; ~EntropyTextureFunctor(){}; typedef TIterInput1 IterType1; @@ -63,86 +57,6 @@ public: typedef std::vector<IntVectorType> IntVectorVectorType; - double GetMaxi(){ return m_Maxi; }; - double GetMini(){ return m_Mini; }; - double GetMaxiOff(){ return m_MaxiOff; }; - double GetMiniOff(){ return m_MiniOff; }; - - /** Computes the histogram bins using Scott formula, plus min/max. */ - DoubleVectorType StatComputation(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) - { - DoubleVectorType output; - double binLength = 0; - double binLengthOff =0; - double mean = 0.; - double meanOff = 0.; - RadiusType radius = neigh.GetRadius(); - m_Mini = itk::NumericTraits<double>::max(); - m_MiniOff = itk::NumericTraits<double>::max(); - m_Maxi = itk::NumericTraits<double>::NonpositiveMin(); - m_MaxiOff = itk::NumericTraits<double>::NonpositiveMin(); - double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]); - double areaInv = 1/area; - double scottCoef = 3.5 /(vcl_pow(area, 1/3) ); - - OffsetType offset; - offset.Fill(0); - OffsetType offsetOff; - OffsetType offsetOffInit; - - offsetOffInit[0] = -radius[0]+this->GetOffset()[0]-1; - offsetOffInit[1] = -radius[1]+this->GetOffset()[1]-1; - - offsetOff = offsetOffInit; - for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) - { - offsetOff[0]++; - offsetOff[1] = offsetOffInit[1]; - offset[0] = l; - for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) - { - offsetOff[1]++; - offset[1] = k; - mean += static_cast<double>(neigh[offset]); - meanOff += static_cast<double>(neighOff[offsetOff]); - - m_Mini = std::min(static_cast<double>(neigh[offset]), m_Mini); - m_Maxi = std::max(static_cast<double>(neigh[offset]), m_Maxi); - m_MiniOff = std::min(static_cast<double>(neighOff[offsetOff]),m_MiniOff); - m_MaxiOff = std::max(static_cast<double>(neighOff[offsetOff]),m_MaxiOff); - } - } - mean *= areaInv; - meanOff *= areaInv; - - offsetOff = offsetOffInit; - - for( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) - { - offsetOff[0]++; - offsetOff[1] = offsetOffInit[1]; - offset[0] = l; - for( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) - { - offsetOff[1]++; - offset[1] = k; - binLength += vcl_pow( (mean-static_cast<double>(neigh[offset])), 2); - binLengthOff += vcl_pow( (meanOff-static_cast<double>(neighOff[offsetOff])), 2); - } - } - - binLength *= areaInv; - binLength = vcl_sqrt( binLength ); - binLengthOff *= areaInv; - binLengthOff = vcl_sqrt( binLengthOff ); - - output.push_back( scottCoef*binLength ); - output.push_back( scottCoef*binLengthOff ); - - return output; - } - - virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) { DoubleVectorType binsLength = this->StatComputation(neigh, neighOff); @@ -165,11 +79,11 @@ public: IntVectorType histoTemp; IntVectorVectorType histo; if (binsLength[0] != 0) - histoTemp = IntVectorType( vcl_floor( static_cast<double>(m_Maxi-m_Mini)/binsLength[0])+1., 0); + histoTemp = IntVectorType( vcl_floor( static_cast<double>(this->GetMaxi()-this->GetMini())/binsLength[0])+1., 0); else histoTemp = IntVectorType( 1, 0 ); if (binsLength[1] != 0) - histo = IntVectorVectorType( vcl_floor(static_cast<double>(m_MaxiOff-m_MiniOff)/binsLength[1])+1., histoTemp ); + histo = IntVectorVectorType( vcl_floor(static_cast<double>(this->GetMaxiOff()-this->GetMiniOff())/binsLength[1])+1., histoTemp ); else histo = IntVectorVectorType( 1, histoTemp ); @@ -186,9 +100,9 @@ public: histoIdX = 0; histoIdY = 0; if ( binsLength[1] != 0) - histoIdX = static_cast<int>(vcl_floor( (static_cast<double>(neighOff[offsetOff])-m_MiniOff) / static_cast<double>(binsLength[1]) )); + histoIdX = static_cast<int>(vcl_floor( (static_cast<double>(neighOff[offsetOff])-this->GetMiniOff()) / static_cast<double>(binsLength[1]) )); if ( binsLength[0] !=0 ) - histoIdY = static_cast<int>(vcl_floor( (static_cast<double>(neigh[offset])-m_Mini) /static_cast<double>( binsLength[0]) )); + histoIdY = static_cast<int>(vcl_floor( (static_cast<double>(neigh[offset])-this->GetMini()) /static_cast<double>( binsLength[0]) )); histo[histoIdX][histoIdY]++; @@ -209,16 +123,6 @@ public: return out; } - - - -private: - /** Stores min/max neighborhood area values */ - double m_Mini; - double m_Maxi; - /** Stores min/max neighborhood+offset values */ - double m_MiniOff; - double m_MaxiOff; }; diff --git a/Code/FeatureExtraction/otbTextureFunctorBase.h b/Code/FeatureExtraction/otbTextureFunctorBase.h index 19980ad08750f2e9fdfd257d7d242405e9d7ff82..ced9ae022f49bcc6245f9771f6fc0e91ce46be73 100644 --- a/Code/FeatureExtraction/otbTextureFunctorBase.h +++ b/Code/FeatureExtraction/otbTextureFunctorBase.h @@ -55,16 +55,111 @@ public: typedef typename IterType1::InternalPixelType InternalPixelType; typedef typename IterType1::ImageType ImageType; typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension> NeighborhoodType; + typedef std::vector<double> DoubleVectorType; void SetOffset(OffsetType off) { m_Offset=off; + m_Mini = itk::NumericTraits<double>::max(); + m_MiniOff = itk::NumericTraits<double>::max(); + m_Maxi = itk::NumericTraits<double>::NonpositiveMin(); + m_MaxiOff = itk::NumericTraits<double>::NonpositiveMin(); + m_Mean = 0.; + m_MeanOff = 0.; + m_Std = 0.; + m_StdOff = 0.; }; + OffsetType GetOffset() { return m_Offset; }; - + + double GetMaxi(){ return m_Maxi; }; + double GetMini(){ return m_Mini; }; + double GetMaxiOff(){ return m_MaxiOff; }; + double GetMiniOff(){ return m_MiniOff; }; + double GetMean(){ return m_Mean; }; + double GetMeanOff(){ return m_MeanOff; }; + double GetStd(){ return m_Std; }; + double GetStdOff(){ return m_StdOff; }; + + /** Computes the histogram bins using Scott formula, plus min/max, means, stds */ + DoubleVectorType StatComputation(const NeighborhoodType &neigh, const NeighborhoodType &neighOff) + { + DoubleVectorType output; + double binLength = 0; + double binLengthOff =0; + m_Mean = 0.; + m_MeanOff = 0.; + m_Std = 0.; + m_StdOff = 0.; + RadiusType radius = neigh.GetRadius(); + m_Mini = itk::NumericTraits<double>::max(); + m_MiniOff = itk::NumericTraits<double>::max(); + m_Maxi = itk::NumericTraits<double>::NonpositiveMin(); + m_MaxiOff = itk::NumericTraits<double>::NonpositiveMin(); + double area = static_cast<double>(neigh.GetSize()[0]*neigh.GetSize()[1]); + double areaInv = 1/area; + double scottCoef = 3.5 /(vcl_pow(area, 1/3) ); + + OffsetType offset; + offset.Fill(0); + OffsetType offsetOff; + OffsetType offsetOffInit; + + offsetOffInit[0] = -radius[0]+this->GetOffset()[0]-1; + offsetOffInit[1] = -radius[1]+this->GetOffset()[1]-1; + + offsetOff = offsetOffInit; + for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) + { + offsetOff[0]++; + offsetOff[1] = offsetOffInit[1]; + offset[0] = l; + for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) + { + offsetOff[1]++; + offset[1] = k; + m_Mean += static_cast<double>(neigh[offset]); + m_MeanOff += static_cast<double>(neighOff[offsetOff]); + + m_Mini = std::min(static_cast<double>(neigh[offset]), m_Mini); + m_Maxi = std::max(static_cast<double>(neigh[offset]), m_Maxi); + m_MiniOff = std::min(static_cast<double>(neighOff[offsetOff]),m_MiniOff); + m_MaxiOff = std::max(static_cast<double>(neighOff[offsetOff]),m_MaxiOff); + } + } + m_Mean *= areaInv; + m_MeanOff *= areaInv; + + offsetOff = offsetOffInit; + + for( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) + { + offsetOff[0]++; + offsetOff[1] = offsetOffInit[1]; + offset[0] = l; + for( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++) + { + offsetOff[1]++; + offset[1] = k; + binLength += vcl_pow( (m_Mean-static_cast<double>(neigh[offset])), 2); + binLengthOff += vcl_pow( (m_MeanOff-static_cast<double>(neighOff[offsetOff])), 2); + } + } + + binLength *= areaInv; + binLength = vcl_sqrt( binLength ); + binLengthOff *= areaInv; + binLengthOff = vcl_sqrt( binLengthOff ); + m_Std = binLength; + m_StdOff = binLengthOff; + output.push_back( scottCoef*binLength ); + output.push_back( scottCoef*binLengthOff ); + + return output; + } inline TOutput operator()(const IterType1 &it, const IterType2 &itOff) { @@ -111,7 +206,18 @@ public: private: OffsetType m_Offset; - + /** Stores min/max neighborhood area values */ + double m_Mini; + double m_Maxi; + /** Stores min/max neighborhood+offset values */ + double m_MiniOff; + double m_MaxiOff; + /** Stores mean of neighborhood+offset */ + double m_Mean; + double m_MeanOff; + /** Stores standard deviation of neighborhood+offset */ + double m_Std; + double m_StdOff; }; diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index b15596b102bb18e7e5af2fffe4353cb9f90e46b1..a3e0d373b8fe49a8c087de0e9aa4812eebcda080 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1051,26 +1051,29 @@ ADD_TEST(feTvTextureFunctorBase ${FEATUREEXTRACTION_TESTS11} -2 # offset[0] 2 # offset[1] ) - + + # ------- otb::EnergyTextureFunctor ------------- ADD_TEST(feTvEnergyTextureFunctor ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvEnergyTextureFunctor.tif ${TEMP}/feTvEnergyTextureFunctor.tif - otbEnergyTextureFunctor + otbTextureFunctor + ENJ ${INPUTDATA}/poupees_sub.png ${TEMP}/feTvEnergyTextureFunctor.tif 5 # radius -2 # offset[0] 2 # offset[1] ) - + # ------- otb::EntropyTextureFunctor ------------- ADD_TEST(feTvEntropyTextureFunctor ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvEntropyTextureFunctor.tif ${TEMP}/feTvEntropyTextureFunctor.tif - otbEntropyTextureFunctor + otbTextureFunctor + ENT #entropy ${INPUTDATA}/poupees_sub.png ${TEMP}/feTvEntropyTextureFunctor.tif 5 # radius @@ -1083,7 +1086,8 @@ ADD_TEST(feTvInverseDifferenceMomentTextureFunctor ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvInverseDifferenceMomentTextureFunctor.tif ${TEMP}/feTvInverseDifferenceMomentTextureFunctor.tif - otbInverseDifferenceMomentTextureFunctor + otbTextureFunctor + IMD #inverse difference moment ${INPUTDATA}/poupees_sub.png ${TEMP}/feTvInverseDifferenceMomentTextureFunctor.tif 5 # radius @@ -1096,7 +1100,8 @@ ADD_TEST(feTvAngularSecondMomentumTextureFunctor ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvAngularSecondMomentumTextureFunctor.tif ${TEMP}/feTvAngularSecondMomentumTextureFunctor.tif - otbAngularSecondMomentumTextureFunctor + otbTextureFunctor + ASM #angular second moment ${INPUTDATA}/poupees_sub.png ${TEMP}/feTvAngularSecondMomentumTextureFunctor.tif 5 # radius @@ -1298,10 +1303,7 @@ otbCloudDetectionFilterNew.cxx otbCloudDetectionFilter.cxx otbSimplifyManyPathListFilter.cxx otbTextureFunctorBase.cxx -otbEnergyTextureFunctor.cxx -otbEntropyTextureFunctor.cxx -otbInverseDifferenceMomentTextureFunctor.cxx -otbAngularSecondMomentumTextureFunctor.cxx +otbTextureFunctor.cxx otbTextureImageFunction.cxx ) diff --git a/Testing/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.cxx deleted file mode 100644 index 21782e94cf9c6682abb14689ddda63496c8476fb..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbAngularSecondMomentumTextureFunctor.cxx +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - - 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 "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" -#include "otbVectorImage.h" -#include "itkConstNeighborhoodIterator.h" -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "otbAngularSecondMomentumTextureFunctor.h" - - -int otbAngularSecondMomentumTextureFunctor(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::VectorImage<InputPixelType,Dimension> ImageType; - typedef ImageType::PixelType PixelType; - typedef ImageType::OffsetType OffsetType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; - - typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef otb::Functor::AngularSecondMomentumTextureFunctor<IterType, IterType, PixelType> FunctorType; - typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; - - // Instantiating object - UnaryFunctorNeighborhoodImageFilterType::Pointer object = UnaryFunctorNeighborhoodImageFilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - object->SetInput(reader->GetOutput()); - object->SetRadius(atoi(argv[3])); - OffsetType offset; - offset[0] = atoi(argv[4]); - offset[1] = atoi(argv[5]); - - object->SetOffset(offset); - writer->SetInput(object->GetOutput()); - - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbEnergyTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbEnergyTextureFunctor.cxx deleted file mode 100644 index ad0125ee8bd835e4da80d2d3060949a0f6cba87f..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEnergyTextureFunctor.cxx +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - - 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 "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" -#include "otbVectorImage.h" -#include "itkConstNeighborhoodIterator.h" -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "otbEnergyTextureFunctor.h" - - -int otbEnergyTextureFunctor(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::VectorImage<InputPixelType,Dimension> ImageType; - typedef ImageType::PixelType PixelType; - typedef ImageType::OffsetType OffsetType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; - - typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef otb::Functor::EnergyTextureFunctor<IterType, IterType, PixelType> FunctorType; - typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; - - // Instantiating object - UnaryFunctorNeighborhoodImageFilterType::Pointer object = UnaryFunctorNeighborhoodImageFilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - object->SetInput(reader->GetOutput()); - object->SetRadius(atoi(argv[3])); - OffsetType offset; - offset[0] = atoi(argv[4]); - offset[1] = atoi(argv[5]); - - object->SetOffset(offset); - writer->SetInput(object->GetOutput()); - - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbEntropyTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbEntropyTextureFunctor.cxx deleted file mode 100644 index fbaaaf0e8f73118b30ef5decd4cb32f31fcb2d4e..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEntropyTextureFunctor.cxx +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - - 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 "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" -#include "otbVectorImage.h" -#include "itkConstNeighborhoodIterator.h" -#include "otbImageFileReader.h" -#include "otbStreamingImageFileWriter.h" -#include "otbEntropyTextureFunctor.h" - - -int otbEntropyTextureFunctor(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::VectorImage<InputPixelType,Dimension> ImageType; - typedef ImageType::PixelType PixelType; - typedef ImageType::OffsetType OffsetType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::StreamingImageFileWriter<ImageType> WriterType; - - typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef otb::Functor::EntropyTextureFunctor<IterType, IterType, PixelType> FunctorType; - typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; - - // Instantiating object - UnaryFunctorNeighborhoodImageFilterType::Pointer object = UnaryFunctorNeighborhoodImageFilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - object->SetInput(reader->GetOutput()); - object->SetRadius(atoi(argv[3])); - OffsetType offset; - offset[0] = atoi(argv[4]); - offset[1] = atoi(argv[5]); - - object->SetOffset(offset); - writer->SetInput(object->GetOutput()); - - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx index b7dfc449e000543ee7b721f9fbb2e7fe3339fa58..f822c40db151853b6ba9386ecf3006da6e7b48c5 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx @@ -34,9 +34,6 @@ REGISTER_TEST(otbCloudDetectionFilterNew); REGISTER_TEST(otbCloudDetectionFilter); REGISTER_TEST(otbSimplifyManyPathListFilter); REGISTER_TEST(otbTextureFunctorBase); -REGISTER_TEST(otbEnergyTextureFunctor); -REGISTER_TEST(otbEntropyTextureFunctor); -REGISTER_TEST(otbInverseDifferenceMomentTextureFunctor); -REGISTER_TEST(otbAngularSecondMomentumTextureFunctor); +REGISTER_TEST(otbTextureFunctor); REGISTER_TEST(otbTextureImageFunction); } diff --git a/Testing/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.cxx deleted file mode 100644 index ea15dc4d902f383e348e209b9458e10cb106dced..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbInverseDifferenceMomentTextureFunctor.cxx +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - - 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 "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" -#include "otbVectorImage.h" -#include "itkConstNeighborhoodIterator.h" -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "otbInverseDifferenceMomentTextureFunctor.h" - - -int otbInverseDifferenceMomentTextureFunctor(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::VectorImage<InputPixelType,Dimension> ImageType; - typedef ImageType::PixelType PixelType; - typedef ImageType::OffsetType OffsetType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<ImageType> WriterType; - - typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; - typedef otb::Functor::InverseDifferenceMomentTextureFunctor<IterType, IterType, PixelType> FunctorType; - typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType; - - // Instantiating object - UnaryFunctorNeighborhoodImageFilterType::Pointer object = UnaryFunctorNeighborhoodImageFilterType::New(); - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - object->SetInput(reader->GetOutput()); - object->SetRadius(atoi(argv[3])); - OffsetType offset; - offset[0] = atoi(argv[4]); - offset[1] = atoi(argv[5]); - - object->SetOffset(offset); - writer->SetInput(object->GetOutput()); - - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cf2baca2b04ece85b6ce0004685993809d162207 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx @@ -0,0 +1,104 @@ +/*========================================================================= + + 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 "otbUnaryFunctorNeighborhoodWithOffsetImageFilter.h" +#include "otbVectorImage.h" +#include "itkConstNeighborhoodIterator.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +// Functors list +#include "otbEnergyTextureFunctor.h" +#include "otbEntropyTextureFunctor.h" +#include "otbInverseDifferenceMomentTextureFunctor.h" +#include "otbAngularSecondMomentumTextureFunctor.h" + +template<class TInputImage, class TOutputImage, class TFunctor> +int generic_TextureFunctor(int argc, char * argv[]) +{ + const char * inputFileName = argv[1]; + const char * outputFileName = argv[2]; + + typedef typename TInputImage::SizeType SizeType; + typedef typename TInputImage::OffsetType OffsetType; + typedef otb::ImageFileReader<TInputImage> ReaderType; + typedef otb::StreamingImageFileWriter<TOutputImage> WriterType; + + typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<TInputImage, TOutputImage, TFunctor> FilterType; + + // Instantiating object + typename FilterType::Pointer object = FilterType::New(); + typename ReaderType::Pointer reader = ReaderType::New(); + typename WriterType::Pointer writer = WriterType::New(); + reader->SetFileName(inputFileName); + writer->SetFileName(outputFileName); + + object->SetInput(reader->GetOutput()); + object->SetRadius(atoi(argv[3])); + OffsetType offset; + offset[0] = atoi(argv[4]); + offset[1] = atoi(argv[5]); + + object->SetOffset(offset); + writer->SetInput(object->GetOutput()); + + writer->Update(); + + return EXIT_SUCCESS; +} + +int otbTextureFunctor(int argc, char * argv[]) +{ + std::string strArgv(argv[1]); + argc--; + argv++; + + typedef double InputPixelType; + const int Dimension = 2; + typedef otb::VectorImage<InputPixelType,Dimension> ImageType; + typedef ImageType::PixelType PixelType; + typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType; + + if(strArgv == "ENJ") + { + typedef otb::Functor::EnergyTextureFunctor<IteratorType, IteratorType, PixelType> FunctorType; + return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else if ( strArgv == "ENT" ) + { + typedef otb::Functor::EntropyTextureFunctor<IteratorType, IteratorType, PixelType> FunctorType; + return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else if ( strArgv == "IMD" ) + { + typedef otb::Functor::InverseDifferenceMomentTextureFunctor<IteratorType, IteratorType, PixelType> FunctorType; + return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else if ( strArgv == "ASM" ) + { + typedef otb::Functor::AngularSecondMomentumTextureFunctor<IteratorType, IteratorType, PixelType> FunctorType; + return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +}