diff --git a/Code/BasicFilters/otbCountImageFilter.h b/Code/BasicFilters/otbCountImageFilter.h index 22fb09071007885e5534670d39d0d7d34c668c01..df4905853bfc0c577317bdeff71219ec5421b738 100644 --- a/Code/BasicFilters/otbCountImageFilter.h +++ b/Code/BasicFilters/otbCountImageFilter.h @@ -61,8 +61,9 @@ namespace otb typedef typename InputImageType::IndexType IndexType; /** OutputImageType typedef support*/ - typedef TOutputImage OutputImageType; + typedef typename Superclass::OutputImageType OutputImageType; typedef typename OutputImageType::Pointer OutputImagePointerType; + typedef typename OutputImageType::RegionType OutputImageRegionType; typedef typename OutputImageType::PixelType OutputPixelType; typedef typename itk::NumericTraits< OutputPixelType>::RealType OutputRealType; @@ -105,8 +106,7 @@ namespace otb /** * Main computation method. */ - virtual void GenerateData(); - + virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); private: diff --git a/Code/BasicFilters/otbCountImageFilter.txx b/Code/BasicFilters/otbCountImageFilter.txx index 0d5cfee76a188b3dcf9edfc5b4f66637db0b3238..cb9363f91120af4e764f574cf03420a8e60be58d 100644 --- a/Code/BasicFilters/otbCountImageFilter.txx +++ b/Code/BasicFilters/otbCountImageFilter.txx @@ -31,6 +31,7 @@ namespace otb CountImageFilter<TInputImage , TDetector, TCount, TOutputImage> ::CountImageFilter() { + this->SetNumberOfRequiredInputs( 1 ); m_CountImageFunction = CountImageFunctionType::New(); m_NeighborhoodRadius = 1; } @@ -44,21 +45,25 @@ namespace otb ::~CountImageFilter() {} - /*------------------------------------------------------- - * Generate Data - --------------------------------------------------------*/ + /** + * threaded 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(); + /** + * ThreadedGenerateData Performs the pixel-wise addition + */ +template <class TInputImage , class TDetector, class TCount, class TOutputImage> +void +CountImageFilter<TInputImage, TDetector, TCount, TOutputImage > +::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, int threadId ) +{ + typename Superclass::OutputImagePointer outputImage = this->GetOutput(); + InputImagePointerType ptr = const_cast<InputImageType *>(this->GetInput()); + + /** Update the radius for the CountImageFunction */ + m_CountImageFunction->SetInputImage(ptr); + m_CountImageFunction->SetNeighborhoodRadius(m_NeighborhoodRadius); - /** Update the radius for the CountImageFunction */ - m_CountImageFunction->SetNeighborhoodRadius(this->GetNeighborhoodRadius()); itk::ImageRegionIterator<InputImageType> itInput(ptr, ptr->GetLargestPossibleRegion()); @@ -66,7 +71,7 @@ namespace otb itk::ImageRegionIterator<OutputImageType> itOutput(outputImage, outputImage->GetLargestPossibleRegion()); - CountMethodType CountMethod; + CountMethodType CountMethod; itInput.GoToBegin(); itOutput.GoToBegin(); @@ -74,15 +79,16 @@ namespace otb while(!itInput.IsAtEnd() && !itOutput.IsAtEnd()) { IndexType index = itInput.GetIndex(); - itOutput.Set(m_CountImageFunction->EvaluateAtIndex(index)); + //std::cout <<"Index "<< index <<std::endl; + float value = 0.;//m_CountImageFunction->EvaluateAtIndex(index); + itOutput.Set(value); ++itInput; ++itOutput; } - - - }/** End of GenerateData()*/ - + + +} /** diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 9a6ecc930308d6442b313409c03c17e6cc6b0929..4b57269e47d4bd3ecffc736081d55dc4d24be357 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -1134,6 +1134,15 @@ ADD_TEST(bfTuCountImageFilterNew ${BASICFILTERS_TESTS11} otbCountImageFilterNew ) +ADD_TEST(bfTvCountImageFilterOutputImage ${BASICFILTERS_TESTS11} +--compare-image ${TOL} + ${BASELINE_FILES}/bfTvCountImageFilterOutputImage.tif + ${TEMP}/bfTvCountImageFilterOutputImage.tif + otbCountImageFilterTest + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/bfTvCountImageFilterOutputImage.tif + 5 2 +) # A enrichir SET(BasicFilters_SRCS1 @@ -1298,6 +1307,7 @@ otbExtractROIResample.cxx otbCountImageFunctionNew.cxx otbCountImageFunctionTest.cxx otbCountImageFilterNew.cxx +otbCountImageFilterTest.cxx ) diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx index 07396aa66034ac9354c2dacce87419103a18e64a..66c127df73d5cecf781526c49c136c62c43dbd4b 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx @@ -31,4 +31,5 @@ REGISTER_TEST(otbExtractROIResample); REGISTER_TEST(otbCountImageFunctionNew); REGISTER_TEST(otbCountImageFunctionTest); REGISTER_TEST(otbCountImageFilterNew); +REGISTER_TEST(otbCountImageFilterTest); } diff --git a/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx b/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..68711a0a8dc84b8eb59b4f78fc341ad0b21487d9 --- /dev/null +++ b/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx @@ -0,0 +1,87 @@ +/*========================================================================= + +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 "otbImageFileWriter.h" + +#include <stdio.h> +#include "otbCountImageFilter.h" +#include "otbSiftFastImageFilter.h" +#include "otbSimplePointCountStrategy.h" +#include "itkPointSet.h" +#include "itkVariableLengthVector.h" + +#include <iostream> + +int otbCountImageFilterTest(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 otb::ImageFileWriter<ImageType> WriterType; + + 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; + + + /** 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*/ + FilterType::Pointer filter = FilterType::New(); + + /** Instanciation of the detector : */ + DetectorType::Pointer detector = filter->GetDetector(); + detector->SetNumberOfScales(scales); + + + filter->SetInput(reader->GetOutput()); + filter->SetNeighborhoodRadius(radius); + filter->SetDetector(detector); /*Set the number of scales for the detector**/ + + + /** Output*/ + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outfname); + writer->SetInput(filter->GetOutput()); + writer->Update(); + + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/BasicFilters/otbCountImageFunction.cxx b/Testing/Code/BasicFilters/otbCountImageFunction.cxx deleted file mode 100644 index 1edc301a424ffa72f34428d26521b4a762f629c2..0000000000000000000000000000000000000000 --- a/Testing/Code/BasicFilters/otbCountImageFunction.cxx +++ /dev/null @@ -1,50 +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 <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; -} -