diff --git a/Code/FeatureExtraction/otbTextureImageFunction.h b/Code/FeatureExtraction/otbTextureImageFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..0588f7ec5535302c283a20bdfeea83359c7c9380 --- /dev/null +++ b/Code/FeatureExtraction/otbTextureImageFunction.h @@ -0,0 +1,124 @@ +/*========================================================================= + + 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 __otbTextureImageFunction_h +#define __otbTextureImageFunction_h + +#include "itkImageFunction.h" +#include "itkNumericTraits.h" +#include "itkConstNeighborhoodIterator.h" +#include "itkVariableLengthVector.h" + + +namespace otb +{ + +/** + * \class EnergyImageFunction + * \brief Calculate the energy in the neighborhood of a pixel + * + * This class is templated over the input image type and the + * coordinate representation type (e.g. float or double ). + * + * \ingroup ImageFunctions + */ +template <class TInputImage, class TFunctor, class TCoordRep = float > +class ITK_EXPORT TextureImageFunction : + public itk::ImageFunction< TInputImage, ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType>::RealType, TCoordRep > +{ + public: + /** Standard class typedefs. */ + typedef TextureImageFunction Self; + typedef itk::ImageFunction<TInputImage, ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType>::RealType, + TCoordRep > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(TextureImageFunction, itk::ImageFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** typedef support. */ + typedef TInputImage InputImageType; + typedef TFunctor FunctorType; + typedef typename InputImageType::OffsetType OffsetType; + typedef typename InputImageType::SizeType SizeType; + typedef typename InputImageType::PixelType PixelType; + typedef typename Superclass::OutputType OutputType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef itk::ConstNeighborhoodIterator<InputImageType> IteratorType; + typedef typename IteratorType::NeighborhoodType NeighborhoodType; + typedef typename itk::NumericTraits<typename InputImageType::PixelType>::RealType RealType; + + + /** Dimension of the underlying image. */ + itkStaticConstMacro(ImageDimension, unsigned int,InputImageType::ImageDimension); + + + /** Evalulate the function at specified index */ + virtual RealType EvaluateAtIndex( const IndexType& index ) const; + + /** Evaluate the function at non-integer positions */ + virtual RealType Evaluate( const PointType& point ) const + { + IndexType index; + this->ConvertPointToNearestIndex( point, index ); + return this->EvaluateAtIndex( index ); + } + virtual RealType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex ) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex( cindex, index ); + return this->EvaluateAtIndex( index ) ; + } + + /** Get/Set the radius of the neighborhood over which the + statistics are evaluated */ + itkSetMacro( Radius, SizeType); + itkGetMacro( Radius, SizeType); + itkSetMacro( Offset, OffsetType); + itkGetMacro( Offset, OffsetType ); + +protected: + TextureImageFunction(); + ~TextureImageFunction() {}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + TextureImageFunction( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented + + SizeType m_Radius; + OffsetType m_Offset; + +}; + +} // end namespace otb + + + +#ifndef OTB_MANUAL_INSTANTIATION +# include "otbTextureImageFunction.txx" +#endif + +#endif + diff --git a/Code/FeatureExtraction/otbTextureImageFunction.txx b/Code/FeatureExtraction/otbTextureImageFunction.txx new file mode 100644 index 0000000000000000000000000000000000000000..ea068b130ce55dfad6e54a027bb5be8eb414c5e6 --- /dev/null +++ b/Code/FeatureExtraction/otbTextureImageFunction.txx @@ -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. + +=========================================================================*/ +#ifndef __otbTextureImageFunction_txx +#define __otbTextureImageFunction_txx + +#include "otbTextureImageFunction.h" + + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage, class TFunctor, class TCoordRep> +TextureImageFunction<TInputImage, TFunctor, TCoordRep> +::TextureImageFunction() +{ + m_Radius.Fill(0); + m_Offset.Fill(0); +} + + +/** + * + */ +template <class TInputImage, class TFunctor, class TCoordRep> +void +TextureImageFunction<TInputImage, TFunctor, TCoordRep> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os,indent); + os << indent << "Radius: " << m_Radius << std::endl; + os << indent << "Offset: " << m_Offset << std::endl; +} + + +/** + * + */ +template <class TInputImage, class TFunctor, class TCoordRep> +typename TextureImageFunction<TInputImage, TFunctor, TCoordRep> +::RealType +TextureImageFunction<TInputImage, TFunctor, TCoordRep> +::EvaluateAtIndex(const IndexType& index) const +{ + if ( !this->GetInputImage() ) + { + return ( itk::NumericTraits<RealType>::max() ); + } + + if ( !this->IsInsideBuffer( index ) ) + { + return ( itk::NumericTraits<RealType>::max() ); + } + + IteratorType it(m_Radius, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion()); + it.SetLocation(index); + SizeType radiusOff; + radiusOff[0] = m_Radius[0] + vcl_abs(m_Offset[0]); + radiusOff[1] = m_Radius[1] + vcl_abs(m_Offset[1]); + IteratorType itOff(radiusOff, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion()); + itOff.SetLocation(index); + + FunctorType funct; + funct.SetOffset(m_Offset); + + return static_cast<RealType>(funct.ComputeOverSingleChannel( it.GetNeighborhood(), itOff.GetNeighborhood()) ); +} + + +} // end namespace otb + +#endif diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 2f728ba6f85c7b514a3ab089e573672123c32ad1..12dac3464b6b877959f5877240dec46534c72494 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1066,14 +1066,12 @@ ADD_TEST(feTvEntropyTextureFunctor ${FEATUREEXTRACTION_TESTS11} ) # ------- otb::EnergyTextureImageFunction ------------- -ADD_TEST(feTvEnergyTextureImageFunctionNew ${FEATUREEXTRACTION_TESTS11} - otbEnergyTextureImageFunctionNew -) ADD_TEST(feTvEnergyTextureImageFunction ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvEnergyTextureImageFunction.tif ${TEMP}/feTvEnergyTextureImageFunction.tif - otbEnergyTextureImageFunction + otbTextureImageFunction + ENJ #energy ${INPUTDATA}/poupees_1canal.c1.hdr ${TEMP}/feTvEnergyTextureImageFunction.tif 5 # radius[0] @@ -1084,14 +1082,12 @@ ADD_TEST(feTvEnergyTextureImageFunction ${FEATUREEXTRACTION_TESTS11} # ------- otb::EntropyTextureImageFunction ------------- -ADD_TEST(feTuEntropyTextureImageFunctionNew ${FEATUREEXTRACTION_TESTS11} - otbEntropyTextureImageFunctionNew -) ADD_TEST(feTvEntropyTextureImageFunction ${FEATUREEXTRACTION_TESTS11} --compare-image ${EPS} ${BASELINE}/feTvEntropyTextureImageFunction.tif ${TEMP}/feTvEntropyTextureImageFunction.tif - otbEntropyTextureImageFunction + otbTextureImageFunction + ENT #entropy ${INPUTDATA}/poupees_1canal.c1.hdr ${TEMP}/feTvEntropyTextureImageFunction.tif 5 # radius[0] @@ -1231,11 +1227,8 @@ otbCloudDetectionFilterNew.cxx otbCloudDetectionFilter.cxx otbSimplifyManyPathListFilter.cxx otbEnergyTextureFunctor.cxx -otbEnergyTextureImageFunctionNew.cxx -otbEnergyTextureImageFunction.cxx otbEntropyTextureFunctor.cxx -otbEntropyTextureImageFunctionNew.cxx -otbEntropyTextureImageFunction.cxx +otbTextureImageFunction.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx deleted file mode 100644 index f8b9e319147c18a393dc6af9d3a85f5311541fcc..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx +++ /dev/null @@ -1,72 +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 "otbFunctionWithNeighborhoodToImageFilter.h" -#include "otbEntropyTextureImageFunction.h" -#include "otbImage.h" -#include "otbImageFileReader.h" -#include "otbStreamingImageFileWriter.h" - - -int otbEntropyTextureImageFunction(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::Image<InputPixelType,Dimension> ImageType; - typedef ImageType::SizeType SizeType; - typedef ImageType::OffsetType OffsetType; - - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::StreamingImageFileWriter<ImageType> WriterType; - - typedef otb::EntropyTextureImageFunction<ImageType> FunctionType; - typedef otb::FunctionWithNeighborhoodToImageFilter<ImageType, ImageType, FunctionType> FilterType; - - FunctionType::Pointer energyFunction = FunctionType::New(); - FilterType::Pointer filter = FilterType::New(); - - - // Instantiating object - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - filter->SetInput(reader->GetOutput()); - - SizeType radius; - radius[0] = atoi(argv[3]); - radius[1] = atoi(argv[4]); - energyFunction->SetRadius(radius); - OffsetType offset; - offset[0] = atoi(argv[5]); - offset[1] = atoi(argv[6]); - energyFunction->SetOffset(offset); - - filter->SetFunction(energyFunction); - writer->SetInput(filter->GetOutput()); - writer->SetNumberOfStreamDivisions(1); - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunctionNew.cxx b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunctionNew.cxx deleted file mode 100644 index ba481f761117554ed01eead976d820e54d911eb2..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunctionNew.cxx +++ /dev/null @@ -1,39 +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 "otbEntropyTextureImageFunction.h" -#include "otbImage.h" - - -int otbEntropyTextureImageFunctionNew(int argc, char * argv[]) -{ - //const char * inputFileName = argv[1]; - //const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::Image<InputPixelType,Dimension> ImageType; - typedef otb::EntropyTextureImageFunction<ImageType> EntropyTextureImageFunctionType; - - EntropyTextureImageFunctionType::Pointer entropy = EntropyTextureImageFunctionType::New(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunction.cxx deleted file mode 100644 index 5df9617113bf22f759702b5f2e87b43a4ee3f6b7..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunction.cxx +++ /dev/null @@ -1,72 +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 "otbFunctionWithNeighborhoodToImageFilter.h" -#include "otbEnergyTextureImageFunction.h" -#include "otbImage.h" -#include "otbImageFileReader.h" -#include "otbStreamingImageFileWriter.h" - - -int otbEnergyTextureImageFunction(int argc, char * argv[]) -{ - const char * inputFileName = argv[1]; - const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::Image<InputPixelType,Dimension> ImageType; - typedef ImageType::SizeType SizeType; - typedef ImageType::OffsetType OffsetType; - - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::StreamingImageFileWriter<ImageType> WriterType; - - typedef otb::EnergyTextureImageFunction<ImageType> FunctionType; - typedef otb::FunctionWithNeighborhoodToImageFilter<ImageType, ImageType, FunctionType> FilterType; - - FunctionType::Pointer energyFunction = FunctionType::New(); - FilterType::Pointer filter = FilterType::New(); - - - // Instantiating object - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - reader->SetFileName(inputFileName); - writer->SetFileName(outputFileName); - - filter->SetInput(reader->GetOutput()); - - SizeType radius; - radius[0] = atoi(argv[3]); - radius[1] = atoi(argv[4]); - energyFunction->SetRadius(radius); - OffsetType offset; - offset[0] = atoi(argv[5]); - offset[1] = atoi(argv[6]); - energyFunction->SetOffset(offset); - - filter->SetFunction(energyFunction); - writer->SetInput(filter->GetOutput()); - writer->SetNumberOfStreamDivisions(1); - writer->Update(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunctionNew.cxx b/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunctionNew.cxx deleted file mode 100644 index 7397bf4bacd3765e90f199fb42b547850ee15fb3..0000000000000000000000000000000000000000 --- a/Testing/Code/FeatureExtraction/otbEntropyTextureImageFunctionNew.cxx +++ /dev/null @@ -1,44 +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 "otbFunctionWithNeighborhoodToImageFilter.h" -#include "otbEnergyTextureImageFunction.h" -#include "otbImage.h" -//#include "otbImageFileReader.h" -//#include "otbImageFileWriter.h" - - -int otbEnergyTextureImageFunctionNew(int argc, char * argv[]) -{ - //const char * inputFileName = argv[1]; - //const char * outputFileName = argv[2]; - - typedef double InputPixelType; - const int Dimension = 2; - typedef otb::Image<InputPixelType,Dimension> ImageType; - typedef ImageType::PixelType PixelType; - typedef ImageType::OffsetType OffsetType; - - typedef otb::EnergyTextureImageFunction<ImageType> EnergyTextureImageFunctionType; - - EnergyTextureImageFunctionType::Pointer energy = EnergyTextureImageFunctionType::New(); - - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx index 80e54914627ffe770cb33dd70b0bd22b0e629932..e3cd5c1747d8a54c2cba9d18d926c8df43c7d79c 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(otbEnergyTextureFunctor); -REGISTER_TEST(otbEnergyTextureImageFunctionNew); -REGISTER_TEST(otbEnergyTextureImageFunction); REGISTER_TEST(otbEntropyTextureFunctor); -REGISTER_TEST(otbEntropyTextureImageFunctionNew); -REGISTER_TEST(otbEntropyTextureImageFunction); +REGISTER_TEST(otbTextureImageFunction); } diff --git a/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c751a4aff750cb4de13ce662f063fb80487bf4a3 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx @@ -0,0 +1,108 @@ +/*========================================================================= + + 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 "otbFunctionWithNeighborhoodToImageFilter.h" +#include "otbTextureImageFunction.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "itkConstNeighborhoodIterator.h" +#include "itkVariableLengthVector.h" + + +// Functors list +#include "otbEnergyTextureFunctor.h" +#include "otbEntropyTextureFunctor.h" + +template<class TInputImage, class TOutputImage, class TFunctor> +int generic_TextureImageFunction(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::TextureImageFunction<TInputImage, TFunctor> FunctionType; + typedef otb::FunctionWithNeighborhoodToImageFilter<TInputImage, TOutputImage, FunctionType> FilterType; + + typename FunctionType::Pointer energyFunction = FunctionType::New(); + typename FilterType::Pointer filter = FilterType::New(); + + + // Instantiating object + typename ReaderType::Pointer reader = ReaderType::New(); + typename WriterType::Pointer writer = WriterType::New(); + reader->SetFileName(inputFileName); + writer->SetFileName(outputFileName); + + filter->SetInput(reader->GetOutput()); + + SizeType radius; + radius[0] = atoi(argv[3]); + radius[1] = atoi(argv[4]); + energyFunction->SetRadius(radius); + OffsetType offset; + offset[0] = atoi(argv[5]); + offset[1] = atoi(argv[6]); + energyFunction->SetOffset(offset); + + filter->SetFunction(energyFunction); + writer->SetInput(filter->GetOutput()); + + writer->Update(); + + + return EXIT_SUCCESS; +} + +int otbTextureImageFunction(int argc, char * argv[]) +{ + std::string strArgv(argv[1]); + argc--; + argv++; + + + typedef double InputPixelType; + const int Dimension = 2; + typedef otb::Image<InputPixelType,Dimension> ImageType; + typedef itk::VariableLengthVector<double> VectorType; + typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType; + + + if(strArgv == "ENJ") + { + std::cout<<"ENEGRY"<<std::endl; + typedef otb::Functor::EnergyTextureFunctor<IteratorType, IteratorType, VectorType> FunctorType; + return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else if ( strArgv == "ENT" ) + { + typedef otb::Functor::EntropyTextureFunctor<IteratorType, IteratorType, VectorType> FunctorType; + return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) ); + } + else + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +}