From 3122d7690b9c2a2e434235aa9e51e5749c741aed Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Tue, 27 Jan 2009 16:47:35 +0100 Subject: [PATCH] ADD: Class CountImageFunction & tests --- Code/BasicFilters/otbCountImageFunction.h | 12 +- Code/BasicFilters/otbCountImageFunction.txx | 56 +++------- Testing/Code/BasicFilters/CMakeLists.txt | 11 +- .../BasicFilters/otbBasicFiltersTests11.cxx | 1 + .../BasicFilters/otbCountImageFunction.cxx | 50 +++++++++ .../otbCountImageFunctionTest.cxx | 103 ++++++++++++++++++ ...KeyPointSetFilterOutputDescriptorAscii.cxx | 3 - 7 files changed, 185 insertions(+), 51 deletions(-) create mode 100644 Testing/Code/BasicFilters/otbCountImageFunction.cxx create mode 100644 Testing/Code/BasicFilters/otbCountImageFunctionTest.cxx diff --git a/Code/BasicFilters/otbCountImageFunction.h b/Code/BasicFilters/otbCountImageFunction.h index 4db9d0389c..fdbd57299a 100644 --- a/Code/BasicFilters/otbCountImageFunction.h +++ b/Code/BasicFilters/otbCountImageFunction.h @@ -77,11 +77,12 @@ public: itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + /** Set the input image (reimplemented since we need to set the detector input) */ + virtual void SetInputImage( const InputImageType * ptr ); - - /** Evalulate the function at specified index */ - virtual RealType EvaluateAtIndex( const IndexType& index ); - virtual RealType EvaluateAtIndex( const IndexType& index ) const; + /** 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 { @@ -112,8 +113,6 @@ protected: CountImageFunction(); ~CountImageFunction(){}; - /**Update method*/ - virtual void Modified(); void PrintSelf(std::ostream& os, itk::Indent indent) const; @@ -127,7 +126,6 @@ private: DetectorPointerType m_Detector; unsigned int m_NeighborhoodRadius; - bool m_HasBeenGenerated; }; } // end namespace otb diff --git a/Code/BasicFilters/otbCountImageFunction.txx b/Code/BasicFilters/otbCountImageFunction.txx index 975297ec9c..b790707f7d 100644 --- a/Code/BasicFilters/otbCountImageFunction.txx +++ b/Code/BasicFilters/otbCountImageFunction.txx @@ -36,11 +36,18 @@ CountImageFunction<TInputImage,TDetector , TCount> { m_NeighborhoodRadius = 1; m_Detector = DetectorType::New(); - - m_HasBeenGenerated = false; } +template <class TInputImage, class TDetector ,class TCount > +void +CountImageFunction< TInputImage, TDetector , TCount > +::SetInputImage(const InputImageType * ptr) +{ + Superclass::SetInputImage(ptr); + m_Detector->SetInput(ptr); +} + /** * */ @@ -61,30 +68,12 @@ template <class TInputImage, class TDetector ,class TCount > typename CountImageFunction< TInputImage, TDetector , TCount > ::RealType CountImageFunction<TInputImage,TDetector , TCount> -::EvaluateAtIndex(const IndexType& index) -{ - // generate data again - if(!m_HasBeenGenerated) - { - m_Detector->SetInput(this->GetInputImage()); - m_Detector->Update(); - m_HasBeenGenerated = true; - - } - // Call the const implementation - return this->EvaluateAtIndex(index); -} - -template <class TInputImage, class TDetector ,class TCount > -typename CountImageFunction< TInputImage, TDetector , TCount > -::RealType -CountImageFunction<TInputImage,TDetector , TCount> -::EvaluateAtIndex(const IndexType& index) const +::EvaluateAtIndex(const IndexType& index) const { + m_Detector->Update(); CountType countDensity; - return countDensity(m_Detector->GetOutput(),this->GetNeighborhoodRadius(),index ); + return countDensity(m_Detector->GetOutput(),m_NeighborhoodRadius,index ); } - /** * SetDetector method */ @@ -94,6 +83,10 @@ CountImageFunction<TInputImage,TDetector , TCount> ::SetDetector( DetectorType* detector) { m_Detector = detector; + if(this->GetInputImage()) + { + m_Detector->SetInput(this->GetInputImage()); + } } /** @@ -107,23 +100,6 @@ CountImageFunction<TInputImage,TDetector , TCount> { return m_Detector; } - -// /** -// * Modified -// */ -template <class TInputImage, class TDetector ,class TCount > -void -CountImageFunction<TInputImage,TDetector , TCount> -::Modified() -{ - m_HasBeenGenerated = false ; - Superclass::Modified(); - m_Detector->Modified(); -} - - - - } // end namespace otb #endif diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 63a0929ed4..a8317545fb 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -1120,7 +1120,15 @@ ADD_TEST(bfTuCountImageFunctionNew ${BASICFILTERS_TESTS11} otbCountImageFunctionNew ) - +ADD_TEST(bfTvCountImageFunction ${BASICFILTERS_TESTS11} +--compare-ascii ${TOL} + ${BASELINE_FILES}/bfTvCountImageFunctionOutputAscii.txt + ${TEMP}/bfTvCountImageFunctionOutputAscii.txt + otbCountImageFunctionTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/bfTvCountImageFunctionOutputAscii.txt + 5 2 +) # A enrichir SET(BasicFilters_SRCS1 @@ -1283,6 +1291,7 @@ ENDIF(USE_FFTWD) SET(BasicFilters_SRCS11 otbExtractROIResample.cxx otbCountImageFunctionNew.cxx +otbCountImageFunctionTest.cxx ) diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx index aec76493c8..18fa0e979a 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx @@ -29,4 +29,5 @@ void RegisterTests() { REGISTER_TEST(otbExtractROIResample); REGISTER_TEST(otbCountImageFunctionNew); +REGISTER_TEST(otbCountImageFunctionTest); } diff --git a/Testing/Code/BasicFilters/otbCountImageFunction.cxx b/Testing/Code/BasicFilters/otbCountImageFunction.cxx new file mode 100644 index 0000000000..1edc301a42 --- /dev/null +++ b/Testing/Code/BasicFilters/otbCountImageFunction.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 "otbCountImageFunction.h" +#include "otbSiftFastImageFilter.h" +#include "otbSimplePointCountStrategy.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" +#include "otbImage.h" + +int otbCountImageFunctionNew(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::CountImageFunction< ImageType,DetectorType, + CounterType> FunctionType; + + /**Instancitation of an object*/ + FunctionType::Pointer filter = FunctionType::New(); + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/BasicFilters/otbCountImageFunctionTest.cxx b/Testing/Code/BasicFilters/otbCountImageFunctionTest.cxx new file mode 100644 index 0000000000..462646c226 --- /dev/null +++ b/Testing/Code/BasicFilters/otbCountImageFunctionTest.cxx @@ -0,0 +1,103 @@ +/*========================================================================= + +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 "otbImage.h" +#include "otbImageFileReader.h" + +#include <stdio.h> +#include "otbCountImageFunction.h" +#include "otbSiftFastImageFilter.h" +#include "otbSimplePointCountStrategy.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" + +#include <iostream> + +int otbCountImageFunctionTest(int argc, char* argv[] ) +{ + const char * infname = argv[1]; + const char * outfname = argv[2]; + const unsigned char scales = atoi(argv[3]); + const unsigned char radius = atoi(argv[4]); + const unsigned int Dimension = 2; + typedef float PixelType; + + typedef otb::Image< PixelType, Dimension > ImageType; + typedef ImageType::IndexType IndexType; + + typedef otb::ImageFileReader<ImageType> ReaderType; + + 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::CountImageFunction< ImageType,DetectorType, + CounterType> FunctionType; + + + /** Instanciation of the reader */ + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(infname); + reader->Update(); + + ImageType::SizeType size; + size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); + + /**Instancitation of an object*/ + FunctionType::Pointer filter = FunctionType::New(); + + /** Instanciation of the detector : */ + DetectorType::Pointer detector = filter->GetDetector(); + detector->SetNumberOfScales(scales); + + + filter->SetInputImage(reader->GetOutput()); + filter->SetNeighborhoodRadius(radius); + filter->SetDetector(detector); /*Set the number of scales for the detector**/ + + /** First try*/ + ImageType::IndexType index ; + index[0] = size[0]/2 ; + index[1] = size[1]/4; + + std::ofstream outfile(outfname); + outfile << "At Index: " << index << std::endl; + outfile << "\t density :" << filter->EvaluateAtIndex(index) << std::endl; + + /** Second Try*/ + index[0] = size[0]/4 ; + index[1] = size[1]/4; + + outfile << "At Index: " << index << std::endl; + outfile << "\t density :" << filter->EvaluateAtIndex(index) << std::endl; + + /** Third Try*/ + index[0] = size[0]/2 ; + index[1] = size[1]/2; + + outfile << "At Index: " << index << std::endl; + outfile << "\t density :" << filter->EvaluateAtIndex(index) << std::endl; + + outfile.close(); + + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx index a64baa87e0..3af21c0257 100644 --- a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx +++ b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx @@ -118,8 +118,5 @@ int otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii(int argc, char * ar } outfile.close(); - - outfile.close(); - return EXIT_SUCCESS; } -- GitLab