Skip to content
Snippets Groups Projects
Commit 5dedd90c authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH : change testing method for entropy and energy

parent 261529c2
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
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
/*=========================================================================
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
......@@ -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}")
......
/*=========================================================================
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;
}
/*=========================================================================
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;
}
/*=========================================================================
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;
}
......@@ -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);
}
......@@ -18,36 +18,39 @@
#include "itkExceptionObject.h"
#include "otbFunctionWithNeighborhoodToImageFilter.h"
#include "otbEntropyTextureImageFunction.h"
#include "otbTextureImageFunction.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbStreamingImageFileWriter.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkVariableLengthVector.h"
int otbEntropyTextureImageFunction(int argc, char * argv[])
// 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 double InputPixelType;
const int Dimension = 2;
typedef otb::Image<InputPixelType,Dimension> ImageType;
typedef ImageType::SizeType SizeType;
typedef ImageType::OffsetType OffsetType;
typedef typename TInputImage::SizeType SizeType;
typedef typename TInputImage::OffsetType OffsetType;
typedef otb::ImageFileReader<TInputImage> ReaderType;
typedef otb::StreamingImageFileWriter<TOutputImage> WriterType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::StreamingImageFileWriter<ImageType> WriterType;
typedef otb::TextureImageFunction<TInputImage, TFunctor> FunctionType;
typedef otb::FunctionWithNeighborhoodToImageFilter<TInputImage, TOutputImage, FunctionType> FilterType;
typedef otb::EntropyTextureImageFunction<ImageType> FunctionType;
typedef otb::FunctionWithNeighborhoodToImageFilter<ImageType, ImageType, FunctionType> FilterType;
FunctionType::Pointer energyFunction = FunctionType::New();
FilterType::Pointer filter = FilterType::New();
typename FunctionType::Pointer energyFunction = FunctionType::New();
typename FilterType::Pointer filter = FilterType::New();
// Instantiating object
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
typename ReaderType::Pointer reader = ReaderType::New();
typename WriterType::Pointer writer = WriterType::New();
reader->SetFileName(inputFileName);
writer->SetFileName(outputFileName);
......@@ -64,9 +67,42 @@ int otbEntropyTextureImageFunction(int argc, char * argv[])
filter->SetFunction(energyFunction);
writer->SetInput(filter->GetOutput());
writer->SetNumberOfStreamDivisions(1);
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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment