diff --git a/Code/BasicFilters/otbFunctionToImageFilter.txx b/Code/BasicFilters/otbFunctionToImageFilter.txx index 3dec7157db50bdd7ca7112f07b2ef0f88f6f57ce..46bb28a11a66858ab9495084bb431779732dbd0e 100644 --- a/Code/BasicFilters/otbFunctionToImageFilter.txx +++ b/Code/BasicFilters/otbFunctionToImageFilter.txx @@ -72,7 +72,6 @@ FunctionToImageFilter<TInputImage,TOutputImage,TFunction> << " Input is missing :" << inputPtr.GetPointer();) } - m_PixelFunction->SetInputImage(inputPtr); } diff --git a/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.h b/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..968f0e920aa5c8f8f6969c6d6592cc71597e1e1d --- /dev/null +++ b/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.h @@ -0,0 +1,145 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbFunctionWithNeighborhoodToImageFilter_h +#define __otbFunctionWithNeighborhoodToImageFilter_h + +#include "otbFunctionToImageFilter.h" + + + + + + +namespace otb +{ + +/** \class FunctionWithNeighborhoodToImageFilter + * \brief Evaluates a ImageFunction onto a source image + * + * The class walks an input image and evaluates + * the function at every pixel location. The output of the spatial function + * and the pixel type of the output image must be compatible. + * + * Like its parent ImageToImageFilter, this class functions in the filtering + * pipeline and produces a unique output image. + * + * The function hs to inherite from itkImageFunction + * + * \sa SpatialFunctionImageEvaluatorFilter + * \sa SpatialFunctionImageFilter + * \sa ImageFunction + * \ingroup ImageFilters + */ + +template <class TInputImage, class TOutputImage,class TFunction > +class ITK_EXPORT FunctionWithNeighborhoodToImageFilter : + public FunctionToImageFilter<TInputImage,TOutputImage,TFunction> +{ +public: + /** Standard class typedefs. */ + typedef FunctionWithNeighborhoodToImageFilter Self; + typedef FunctionToImageFilter<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(FunctionWithNeighborhoodToImageFilter, FunctionToImageFilter); + + /** Some typedefs. */ + /** Image size typedef. */ + typedef TInputImage InputImageType; + typedef typename InputImageType::ConstPointer InputImageConstPointer; + typedef typename InputImageType::Pointer InputImagePointer; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename InputImageType::PixelType InputImagePixelType; + typedef typename InputImageType::SizeType InputImageSizeType; + typedef typename InputImageType::OffsetType InputImageOffsetType; + typedef TOutputImage OutputImageType; + typedef typename OutputImageType::Pointer OutputImagePointer; + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef typename OutputImageType::PixelType OutputImagePixelType; + /** Type of function. */ + typedef TFunction FunctionType; + typedef typename FunctionType::OutputType FunctionValueType; + typedef typename FunctionType::InputType FunctionPositionType; + + /** Connect one of the operands for pixel-wise addition. */ + //void SetInput( const TInputImage *image); + +/** Set the internal spatial function. */ + void SetFunction( FunctionType* PixelFunction ) + { + Superclass::SetFunction( PixelFunction ); + //m_Radius = this->GetFunction()->GetRadius(); + //m_Offset = this->GetFunction()->GetOffset(); + this->Modified(); + }; + + /** Image dimensions */ + itkStaticConstMacro(InputImageDimension, unsigned int, + TInputImage::ImageDimension); + itkStaticConstMacro(OutputImageDimension, unsigned int, + TOutputImage::ImageDimension); + + /** Accessors */ + itkGetMacro(Radius, InputImageSizeType); + itkGetMacro(Offset, InputImageOffsetType); + +protected: + FunctionWithNeighborhoodToImageFilter(); + virtual ~FunctionWithNeighborhoodToImageFilter() {}; + + void BeforeThreadedGenerateData(); + + void GenerateInputRequestedRegion(); + + /** SpatialFunctionImageFilter can be implemented as a multithreaded filter. + * Therefore, this implementation provides a ThreadedGenerateData() routine + * which is called for each processing thread. The output image data is + * allocated automatically by the superclass prior to calling + * ThreadedGenerateData(). ThreadedGenerateData can only write to the + * portion of the output image specified by the parameter + * "outputRegionForThread" + * + * \sa ImageToImageFilter::ThreadedGenerateData(), + * ImageToImageFilter::GenerateData() */ + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + int threadId ); + +private: + FunctionWithNeighborhoodToImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + + InputImageSizeType m_Radius; + InputImageOffsetType m_Offset; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbFunctionWithNeighborhoodToImageFilter.txx" +#endif + +#endif diff --git a/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.txx b/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..6ea469338e82414632cfbec694eeb712db4d103c --- /dev/null +++ b/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.txx @@ -0,0 +1,140 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbFunctionWithNeighborhoodToImageFilter_txx +#define __otbFunctionWithNeighborhoodToImageFilter_txx + +#include "otbFunctionWithNeighborhoodToImageFilter.h" +#include "otbMacro.h" + +namespace otb +{ + +/** + * Constructor + */ +template<class TInputImage, class TOutputImage, class TFunction > +FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction> +::FunctionWithNeighborhoodToImageFilter() +{ + m_Radius.Fill(0); + m_Offset.Fill(0); +} + + +template <class TInputImage, class TOutputImage, class TFunction > +void +FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction> +::BeforeThreadedGenerateData() +{ + Superclass::BeforeThreadedGenerateData(); + + m_Radius = this->GetFunction()->GetRadius(); + m_Offset = this->GetFunction()->GetOffset(); +} + +template <class TInputImage, class TOutputImage, class TFunction > +void +FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction> +::GenerateInputRequestedRegion() +{ + // call the superclass' implementation of this method + Superclass::GenerateInputRequestedRegion(); + + // get pointers to the input and output + InputImagePointer inputPtr = const_cast< TInputImage * >( this->GetInput()); + OutputImagePointer outputPtr = this->GetOutput(); + + if ( !inputPtr || !outputPtr ) + { + return; + } + // get a copy of the input requested region (should equal the output + // requested region) + InputImageRegionType inputRequestedRegion = inputPtr->GetRequestedRegion(); + + // pad the input requested region by the operator radius + InputImageSizeType maxRad; + maxRad[0] = m_Radius[0] + vcl_abs(m_Offset[0]); + maxRad[1] = m_Radius[0] + vcl_abs(m_Offset[1]); + inputRequestedRegion.PadByRadius( maxRad ); + + // crop the input requested region at the input's largest possible region + if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) ) + { + inputPtr->SetRequestedRegion( inputRequestedRegion ); + return; + } + else + { + // Couldn't crop the region (requested region is outside the largest + // possible region). Throw an exception. + + // store what we tried to request (prior to trying to crop) + inputPtr->SetRequestedRegion( inputRequestedRegion ); + + // build an exception + itk::InvalidRequestedRegionError e(__FILE__, __LINE__); + itk::OStringStream msg; + msg << this->GetNameOfClass() + << "::GenerateInputRequestedRegion()"; + e.SetLocation(msg.str().c_str()); + e.SetDescription("Requested region is (at least partially) outside the largest possible region."); + e.SetDataObject(inputPtr); + throw e; + } +} + + +/** + * ThreadedGenerateData function. Performs the pixel-wise addition + */ +template<class TInputImage, class TOutputImage, class TFunction > +void +FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction> +::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, + int threadId) +{ + // We use dynamic_cast since inputs are stored as DataObjects. + InputImageConstPointer inputPtr = dynamic_cast<const TInputImage*>((itk::ProcessObject::GetInput(0))); + + OutputImagePointer outputPtr = this->GetOutput(0); + + itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, outputRegionForThread); + itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread); + + itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); + + inputIt.GoToBegin(); + outputIt.GoToBegin(); + + while( !inputIt.IsAtEnd() ) + { + //std::cout<<"MOTHER "<<threadId<<" : "<<inputIt.GetIndex()<<" "<<inputIt.Get()<<std::endl; + outputIt.Set( static_cast<OutputImagePixelType>(this->GetFunction()->EvaluateAtIndex(inputIt.GetIndex())) ); + ++inputIt; + ++outputIt; + + progress.CompletedPixel(); // potential exception thrown here + } +} +} // end namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbEnergyTextureFunctor.h b/Code/FeatureExtraction/otbEnergyTextureFunctor.h index 67072913f9d4c8c2c611694abc1e242cabdcb566..e04ed396c383f250749e6ae23d7a8360b73062be 100644 --- a/Code/FeatureExtraction/otbEnergyTextureFunctor.h +++ b/Code/FeatureExtraction/otbEnergyTextureFunctor.h @@ -73,12 +73,9 @@ class EnergyTextureFunctor double temp = 0.; int ll = 0; - //double dist = 0.; double norm = 0.; - //std::cout<<"START : "<<offsetOff<<std::endl; for( unsigned int i=0; i<nbComp; i++ ) { - //std::cout<<"NEEEEEEEEEEEEW :"<<std::endl; offsetOff = offsetOffInit; temp = 0.; for( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ ) @@ -92,12 +89,8 @@ class EnergyTextureFunctor { offsetOff[1]++; offset[1] = k; - //std::cout<<"k="<<k<<" : "<<offset<<" -> "<<offsetOff<<std::endl; - //dist = 1.; - norm = vcl_pow(static_cast<double>(itOff.GetPixel(offsetOff)[i]-itOff.GetCenterPixel()[i]), 2); - - temp += norm; + temp += norm; } temp /= area; outPix[i] = static_cast<OutputPixelType>( vcl_pow(temp, 2) ); @@ -109,11 +102,13 @@ class EnergyTextureFunctor } private: - OffsetType m_Offset;; + OffsetType m_Offset; }; + + } // namespace Functor } // namespace otb diff --git a/Code/FeatureExtraction/otbEnergyTextureImageFunction.h b/Code/FeatureExtraction/otbEnergyTextureImageFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..034fcfa05d5c544c8590ba8bb4fac26bd9d9b390 --- /dev/null +++ b/Code/FeatureExtraction/otbEnergyTextureImageFunction.h @@ -0,0 +1,118 @@ +/*========================================================================= + + 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 __otbEnergyTextureImageFunction_h +#define __otbEnergyTextureImageFunction_h + +#include "itkImageFunction.h" +#include "itkNumericTraits.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 TCoordRep = float > +class ITK_EXPORT EnergyTextureImageFunction : + public itk::ImageFunction< TInputImage, ITK_TYPENAME itk::NumericTraits<typename TInputImage::PixelType>::RealType, TCoordRep > +{ + public: + /** Standard class typedefs. */ + typedef EnergyTextureImageFunction 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(EnergyTextureImageFunction, itk::ImageFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** typedef support. */ + typedef TInputImage InputImageType; + 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 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: + EnergyTextureImageFunction(); + ~EnergyTextureImageFunction(){}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + EnergyTextureImageFunction( 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 "otbEnergyTextureImageFunction.txx" +#endif + +#endif + diff --git a/Code/FeatureExtraction/otbEnergyTextureImageFunction.txx b/Code/FeatureExtraction/otbEnergyTextureImageFunction.txx new file mode 100644 index 0000000000000000000000000000000000000000..c6b3869e7fa9626fc8ada93378b7deebdf149fd8 --- /dev/null +++ b/Code/FeatureExtraction/otbEnergyTextureImageFunction.txx @@ -0,0 +1,134 @@ +/*========================================================================= + + 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 __otbEnergyTextureImageFunction_txx +#define __otbEnergyTextureImageFunction_txx + +#include "otbEnergyTextureImageFunction.h" +#include "itkConstNeighborhoodIterator.h" +#include "otbEnergyTextureFunctor.h" + + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage, class TCoordRep> +EnergyTextureImageFunction<TInputImage,TCoordRep> +::EnergyTextureImageFunction() +{ + m_Radius.Fill(0); + m_Offset.Fill(0); +} + + +/** + * + */ +template <class TInputImage, class TCoordRep> +void +EnergyTextureImageFunction<TInputImage,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 TCoordRep> +typename EnergyTextureImageFunction<TInputImage,TCoordRep> +::RealType +EnergyTextureImageFunction<TInputImage,TCoordRep> +::EvaluateAtIndex(const IndexType& index) const +{ + if( !this->GetInputImage() ) + { + return ( itk::NumericTraits<RealType>::max() ); + } + + if ( !this->IsInsideBuffer( index ) ) + { + return ( itk::NumericTraits<RealType>::max() ); + } + + typedef itk::ConstNeighborhoodIterator<InputImageType> IterType; + IterType 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]); + IterType itOff(radiusOff, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion()); + itOff.SetLocation(index); + + /* + typedef typename Functor::EnergyTextureFunctor<IterType, IterType, RealType> FunctType; + FunctType funct; + funct.SetRadius(m_Radius); + funct.SetOffset(m_Offset); + funct(it, itOff); + //FunctType::operator()(it, itOff); + + return 0; + */ + double area = static_cast<double>(m_Radius[0]*m_Radius[1]); + RealType output; + + OffsetType offset; + offset.Fill(0); + OffsetType offsetOff; + OffsetType offsetOffInit; + + offsetOffInit[0] = -m_Radius[0]+m_Offset[0]-1; //++ in for + offsetOffInit[1] = -m_Radius[1]+m_Offset[1]-1; //++ in for + + double temp = 0.; + int ll = 0; + double norm = 0.; + offsetOff = offsetOffInit; + temp = 0.; + for( int l = -static_cast<int>(m_Radius[0]); l <= static_cast<int>(m_Radius[0]); l++ ) + { + offsetOff[0]++; + offset[0] = l; + ll = l*l; + offsetOff[1] = offsetOffInit[1]; + for( int k = -static_cast<int>(m_Radius[1]); k <= static_cast<int>(m_Radius[1]); k++) + { + offsetOff[1]++; + offset[1] = k; + norm = vcl_pow(static_cast<double>(itOff.GetPixel(offsetOff)-itOff.GetCenterPixel()), 2); + temp += norm; + } + temp /= area; + output = static_cast<RealType>( vcl_pow(temp, 2) ); + } + return output; + + + +} + + +} // end namespace otb + +#endif diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 9a6ecc930308d6442b313409c03c17e6cc6b0929..fd1d1640209f6afb17cf2929be494887abb379ac 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -1135,6 +1135,13 @@ ADD_TEST(bfTuCountImageFilterNew ${BASICFILTERS_TESTS11} ) + +ADD_TEST(bfTvFunctionWithNeighborhoodToImageFilterNew ${BASICFILTERS_TESTS11} + otbFunctionWithNeighborhoodToImageFilterNew +) + + + # A enrichir SET(BasicFilters_SRCS1 otbLeeFilter.cxx @@ -1298,6 +1305,7 @@ otbExtractROIResample.cxx otbCountImageFunctionNew.cxx otbCountImageFunctionTest.cxx otbCountImageFilterNew.cxx +otbFunctionWithNeighborhoodToImageFilterNew.cxx ) diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx index 07396aa66034ac9354c2dacce87419103a18e64a..ad5f02c2108ad7387ec04d00e10f602b44d2a87a 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx @@ -30,5 +30,6 @@ void RegisterTests() REGISTER_TEST(otbExtractROIResample); REGISTER_TEST(otbCountImageFunctionNew); REGISTER_TEST(otbCountImageFunctionTest); -REGISTER_TEST(otbCountImageFilterNew); +REGISTER_TEST(otbCountImageFilterNew); +REGISTER_TEST(otbFunctionWithNeighborhoodToImageFilterNew); } diff --git a/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.cxx b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e7d848b2afba53be48617400147119ce9ebe7a82 --- /dev/null +++ b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilter.cxx @@ -0,0 +1,57 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbFunctionWithNeighborhoodToImageFilter.h" +#include "itkVarianceImageFunction.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +int otbFunctionWithNeighborhoodToImageFilter(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::Image<PixelType,Dimension> InputImageType; + typedef otb::Image<PixelType,Dimension> OutputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::StreamingImageFileWriter<OutputImageType> WriterType; + typedef itk::VarianceImageFunction<InputImageType> FunctionType; + typedef otb::FunctionWithNeighborhoodToImageFilter<InputImageType, OutputImageType, FunctionType> FilterType; + + // Instantiating object + FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + reader->SetFileName(argv[1]); + writer->SetFileName(argv[2]); + filter->SetInput( reader->GetOutput() ); + + FunctionType::Pointer function = FunctionType::New(); + function->SetNeighborhoodRadius(atoi(argv[3])); + function->SetInputImage(reader->GetOutput()); + + filter->SetFunction(function); + + + writer->SetInput(filter->GetOutput()); + writer->SetNumberOfStreamDivisions(1); + writer->Update(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..306f908d50271077781818a0b7870320dba9a8d2 --- /dev/null +++ b/Testing/Code/BasicFilters/otbFunctionWithNeighborhoodToImageFilterNew.cxx @@ -0,0 +1,36 @@ +/*========================================================================= + + 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 "otbImage.h" +#include "otbFunctionWithNeighborhoodToImageFilter.h" +#include "itkVarianceImageFunction.h" + +int otbFunctionWithNeighborhoodToImageFilterNew(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef itk::VarianceImageFunction<ImageType> FunctionType; + + typedef otb::FunctionWithNeighborhoodToImageFilter<ImageType, ImageType, FunctionType> FilterType; + + // Instantiating object + FilterType::Pointer object = FilterType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 9c08843b8a5a22f549a3dfa7c7f391cb39d378f4..3ee643ef01f2375f0165150e469403c79905c75b 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1002,10 +1002,10 @@ ADD_TEST(feTvCloudDetectionFilter ${FEATUREEXTRACTION_TESTS11} # ------- otb::EnergyTextureFunctor ------------- ADD_TEST(feTvEnergyTextureFunctor ${FEATUREEXTRACTION_TESTS11} - otbEnergyTextureFunctor --compare-image ${EPS} ${BASELINE}/feTvEnergyTextureFunctor.tif ${TEMP}/feTvEnergyTextureFunctor.tif + otbEnergyTextureFunctor ${INPUTDATA}/poupees.tif ${TEMP}/feTvEnergyTextureFunctor.tif 5 # radius @@ -1014,6 +1014,23 @@ ADD_TEST(feTvEnergyTextureFunctor ${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 + ${INPUTDATA}/poupees_1canal.c1.hdr + ${TEMP}/feTvEnergyTextureImageFunction.tif + 5 # radius[0] + 5 # radius[1] + -2 # offset[0] + 2 # offset[1] +) + # A enrichir SET(BasicFeatureExtraction_SRCS1 otbAlignImageToPath.cxx @@ -1141,6 +1158,8 @@ SET(BasicFeatureExtraction_SRCS11 otbCloudDetectionFilterNew.cxx otbCloudDetectionFilter.cxx otbEnergyTextureFunctor.cxx +otbEnergyTextureImageFunctionNew.cxx +otbEnergyTextureImageFunction.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0897fc8efc60babe25535c6feef6b4e08c4b1e80 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunction.cxx @@ -0,0 +1,72 @@ +/*========================================================================= + + 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/otbEnergyTextureImageFunctionNew.cxx b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunctionNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..76561c6f9a75c8e80aebb6c8397e57eb0d5b2389 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbEnergyTextureImageFunctionNew.cxx @@ -0,0 +1,67 @@ +/*========================================================================= + + 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::ImageFileReader<ImageType> ReaderType; + // typedef otb::ImageFileWriter<ImageType> WriterType; + + // typedef itk::ConstNeighborhoodIterator<ImageType> IterType;; + // typedef otb::Functor::EnergyTextureFunctor<IterType, IterType, PixelType> FunctorType; + typedef otb::EnergyTextureImageFunction<ImageType> EnergyTextureImageFunctionType; + + EnergyTextureImageFunctionType::Pointer energy = EnergyTextureImageFunctionType::New(); + + // 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 1b1e0dc1f3c4a6a66fced64a830e8d1a47abfc9c..c37f0991ac09e2485109b8443a594fba7660447c 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx @@ -30,4 +30,6 @@ void RegisterTests() REGISTER_TEST(otbCloudDetectionFilterNew); REGISTER_TEST(otbCloudDetectionFilter); REGISTER_TEST(otbEnergyTextureFunctor); +REGISTER_TEST(otbEnergyTextureImageFunctionNew); +REGISTER_TEST(otbEnergyTextureImageFunction); }