diff --git a/Code/BasicFilters/otbCountImageFilter.h b/Code/BasicFilters/otbCountImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..22fb09071007885e5534670d39d0d7d34c668c01 --- /dev/null +++ b/Code/BasicFilters/otbCountImageFilter.h @@ -0,0 +1,127 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + +Copyright (c) CS Systemes d'information. All rights reserved. +See CSCopyright.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 __otbCountImageFilter_h +#define __otbCountImageFilter_h + + +#include "itkImageToImageFilter.h" +#include "itkProcessObject.h" +#include "otbCountImageFunction.h" +#include "itkNumericTraits.h" + + +/** \class CountImageFilter + * \brief This class extracts key points from an image through a pyramidal gaussian based decomposition + + * + */ + +namespace otb +{ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + class ITK_EXPORT CountImageFilter + : public itk::ImageToImageFilter<TInputImage, TOutputImage> + { + + public: + + /** Standard class typedefs. */ + typedef CountImageFilter Self; + typedef itk::ImageToImageFilter<TInputImage,TOutputImage> 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(CountImageFilter,itk::ImageToImageFilter); + + + /** Template parameters typedefs*/ + typedef TInputImage InputImageType; + typedef typename InputImageType::Pointer InputImagePointerType; + typedef typename InputImageType::IndexType IndexType; + + /** OutputImageType typedef support*/ + typedef TOutputImage OutputImageType; + typedef typename OutputImageType::Pointer OutputImagePointerType; + typedef typename OutputImageType::PixelType OutputPixelType; + + typedef typename itk::NumericTraits< OutputPixelType>::RealType OutputRealType; + + /** Detector typedef Support*/ + typedef TDetector DetectorType; + + /** Count Function typedef Support*/ + typedef TCount CountMethodType; + + /** CountImageFunction support*/ + typedef otb::CountImageFunction<InputImageType,DetectorType, + CountMethodType > CountImageFunctionType; + typedef typename CountImageFunctionType::Pointer CountImageFunctionTypePointer; + + /** Get/Set the radius of the neighborhood over which the + statistics are evaluated */ + itkSetMacro( NeighborhoodRadius, unsigned int ); + itkGetConstReferenceMacro( NeighborhoodRadius, unsigned int ); + + + /**Set/Get Descriptor from the otbCountmageFunction*/ + virtual void SetDetector(DetectorType* detector); + virtual DetectorType* GetDetector(); + + protected: + + /** + * Constructor. + */ + CountImageFilter(); + /** + * Destructor. + */ + virtual ~CountImageFilter(); + /** + * Standard PrintSelf method. + */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + /** + * Main computation method. + */ + virtual void GenerateData(); + + + private: + + CountImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + CountImageFunctionTypePointer m_CountImageFunction; + + unsigned int m_NeighborhoodRadius; + }; +} +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbCountImageFilter.txx" +#endif + +#endif + + diff --git a/Code/BasicFilters/otbCountImageFilter.txx b/Code/BasicFilters/otbCountImageFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..0d5cfee76a188b3dcf9edfc5b4f66637db0b3238 --- /dev/null +++ b/Code/BasicFilters/otbCountImageFilter.txx @@ -0,0 +1,126 @@ +/*========================================================================= + +Program: ORFEO Toolbox +Language: C++ +Date: $Date$ +Version: $Revision$ + + +Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. +See OTBCopyright.txt for details. + +Copyright (c) CS systèmes d'information. All rights reserved. +See CSCopyright.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 "otbCountImageFilter.h" +#include "itkImageRegionIterator.h" + + +namespace otb +{ + /**--------------------------------------------------------- + * Constructor + ----------------------------------------------------------*/ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + CountImageFilter<TInputImage , TDetector, TCount, TOutputImage> + ::CountImageFilter() + { + m_CountImageFunction = CountImageFunctionType::New(); + m_NeighborhoodRadius = 1; + } + + + /*--------------------------------------------------------- + * Destructor.c + ----------------------------------------------------------*/ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + CountImageFilter<TInputImage, TDetector, TCount, TOutputImage > + ::~CountImageFilter() + {} + + /*------------------------------------------------------- + * Generate Data + --------------------------------------------------------*/ + + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + void + CountImageFilter<TInputImage, TDetector, TCount, TOutputImage > + ::GenerateData(void) + { + InputImagePointerType ptr = const_cast<InputImageType *>(this->GetInput()); + + OutputImagePointerType outputImage = this->GetOutput(); + + /** Update the radius for the CountImageFunction */ + m_CountImageFunction->SetNeighborhoodRadius(this->GetNeighborhoodRadius()); + + itk::ImageRegionIterator<InputImageType> + itInput(ptr, ptr->GetLargestPossibleRegion()); + + itk::ImageRegionIterator<OutputImageType> + itOutput(outputImage, outputImage->GetLargestPossibleRegion()); + + CountMethodType CountMethod; + + itInput.GoToBegin(); + itOutput.GoToBegin(); + + while(!itInput.IsAtEnd() && !itOutput.IsAtEnd()) + { + IndexType index = itInput.GetIndex(); + itOutput.Set(m_CountImageFunction->EvaluateAtIndex(index)); + + ++itInput; + ++itOutput; + } + + + }/** End of GenerateData()*/ + + + + /** + * Set Detector + */ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + void + CountImageFilter<TInputImage, TDetector, TCount, TOutputImage > + ::SetDetector(DetectorType* detector) + { + m_CountImageFunction->SetDetector(detector); + } + + + /** + * Get Detector + */ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + typename CountImageFilter< TInputImage , TDetector, TCount, TOutputImage > + ::DetectorType * + CountImageFilter< TInputImage , TDetector, TCount, TOutputImage > + ::GetDetector() + { + return m_CountImageFunction->GetDetector(); + } + + + + /*---------------------------------------------------------------- + PrintSelf + -----------------------------------------------------------------*/ + template <class TInputImage , class TDetector, class TCount, class TOutputImage> + void + CountImageFilter< TInputImage , TDetector, TCount, TOutputImage > + ::PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + os << indent << "Neighborhood Radius " << m_NeighborhoodRadius << std::endl; + } + +}/** end namesapce otb*/ diff --git a/Code/BasicFilters/otbCountImageFunction.h b/Code/BasicFilters/otbCountImageFunction.h index fdbd57299ad95061bbd9f663b7bca7b1df93cdbb..b7a7341c41389a78cca79f295172797e6bb5fc15 100644 --- a/Code/BasicFilters/otbCountImageFunction.h +++ b/Code/BasicFilters/otbCountImageFunction.h @@ -29,7 +29,6 @@ namespace otb * \class CountImageFunction * \brief Calculate the density in the neighborhood of a pixel * - * * \ingroup ImageFunctions */ template <class TInputImage, class TDetector, class TCount > diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index a8317545fbc03c2513b866a56f64b614772ece67..9a6ecc930308d6442b313409c03c17e6cc6b0929 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -1129,6 +1129,11 @@ ADD_TEST(bfTvCountImageFunction ${BASICFILTERS_TESTS11} ${TEMP}/bfTvCountImageFunctionOutputAscii.txt 5 2 ) +# ------- otbCountImageFilter ---------------------------- +ADD_TEST(bfTuCountImageFilterNew ${BASICFILTERS_TESTS11} + otbCountImageFilterNew + ) + # A enrichir SET(BasicFilters_SRCS1 @@ -1292,6 +1297,7 @@ SET(BasicFilters_SRCS11 otbExtractROIResample.cxx otbCountImageFunctionNew.cxx otbCountImageFunctionTest.cxx +otbCountImageFilterNew.cxx ) diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx index 18fa0e979aaf7e6e63c8c3ee767e16d5b4e90180..07396aa66034ac9354c2dacce87419103a18e64a 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx @@ -29,5 +29,6 @@ void RegisterTests() { REGISTER_TEST(otbExtractROIResample); REGISTER_TEST(otbCountImageFunctionNew); -REGISTER_TEST(otbCountImageFunctionTest); +REGISTER_TEST(otbCountImageFunctionTest); +REGISTER_TEST(otbCountImageFilterNew); } diff --git a/Testing/Code/BasicFilters/otbCountImageFilterNew.cxx b/Testing/Code/BasicFilters/otbCountImageFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7cb4c01feaf0e8cf773bce135de24556fc30ab13 --- /dev/null +++ b/Testing/Code/BasicFilters/otbCountImageFilterNew.cxx @@ -0,0 +1,50 @@ +/*========================================================================= + +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 <stdio.h> + +#include "otbCountImageFilter.h" +#include "otbSiftFastImageFilter.h" +#include "otbSimplePointCountStrategy.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" +#include "otbImage.h" + +int otbCountImageFilterNew(int, char* [] ) +{ + + const unsigned int Dimension = 2; + typedef float PixelType; + + typedef otb::Image< PixelType, Dimension > ImageType; + typedef ImageType::IndexType IndexType; + typedef itk::VariableLengthVector<PixelType> RealVectorType; + typedef itk::PointSet<RealVectorType,Dimension> PointSetType; + typedef otb::SiftFastImageFilter<ImageType,PointSetType> DetectorType; + + typedef otb::Count<PointSetType,unsigned int ,IndexType> CounterType; + + typedef otb::CountImageFilter< ImageType,DetectorType, + CounterType,ImageType> FilterType; + + /**Instancitation of an object*/ + FilterType::Pointer filter = FilterType::New(); + + return EXIT_SUCCESS; +} +