From 98e0ebc807b164837231d55461329bd206a3c857 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@c-s.fr> Date: Fri, 24 Nov 2006 15:19:08 +0000 Subject: [PATCH] =?UTF-8?q?Correction=20erreur=20dan=20otbTestMain.=20Simp?= =?UTF-8?q?lification=20dans=20les=20filtres=20d'analyse=20et=20de=20synth?= =?UTF-8?q?=C3=A8se=20par=20pyramide=20morphologique.=20Ajout=20de=20la=20?= =?UTF-8?q?restitution=20des=20d=C3=A9tails=20de=20la=20pyramide=20=C3=A0?= =?UTF-8?q?=20pleine=20r=C3=A9solution.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/Common/otbImageToImageListFilter.h | 2 +- Code/Common/otbObjectList.h | 23 +++- Code/Common/otbObjectList.txx | 34 ++++++ Code/Common/otbTestMain.h | 4 +- .../otbMorphologicalPyramidAnalyseFilter.h | 9 -- .../otbMorphologicalPyramidAnalyseFilter.txx | 23 +--- .../otbMorphologicalPyramidMRToMSConverter.h | 108 +++++++++++++++++ ...otbMorphologicalPyramidMRToMSConverter.txx | 93 +++++++++++++++ .../otbMorphologicalPyramidResampler.h | 2 +- .../otbMorphologicalPyramidResampler.txx | 62 +--------- .../otbMorphologicalPyramidSynthesisFilter.h | 7 -- ...otbMorphologicalPyramidSynthesisFilter.txx | 40 ++++--- Testing/Code/Common/CMakeLists.txt | 6 + Testing/Code/Common/otbCommonTests.cxx | 1 + Testing/Code/Common/otbObjectList.cxx | 19 +++ Testing/Code/MultiScale/CMakeLists.txt | 30 ++++- ...otbMorphologicalPyramidMRToMSConverter.cxx | 109 ++++++++++++++++++ ...MorphologicalPyramidMRToMSConverterNew.cxx | 54 +++++++++ .../otbMorphologicalPyramidResampler.cxx | 7 -- ...otbMorphologicalPyramidSynthesisFilter.cxx | 8 ++ .../Code/MultiScale/otbMultiScaleTests.cxx | 2 + 21 files changed, 514 insertions(+), 129 deletions(-) create mode 100644 Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.h create mode 100644 Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.txx create mode 100644 Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.cxx create mode 100644 Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverterNew.cxx diff --git a/Code/Common/otbImageToImageListFilter.h b/Code/Common/otbImageToImageListFilter.h index cc17786fed..a7eb49d453 100644 --- a/Code/Common/otbImageToImageListFilter.h +++ b/Code/Common/otbImageToImageListFilter.h @@ -22,7 +22,7 @@ PURPOSE. See the above copyright notices for more information. namespace otb { -/** \class ImageListSource +/** \class ImageToImageListFilter * \brief Base class for all the filters taking an image input * to produce an image list. * \ingroup Images diff --git a/Code/Common/otbObjectList.h b/Code/Common/otbObjectList.h index d1bfa1eb75..c977d4d5b0 100644 --- a/Code/Common/otbObjectList.h +++ b/Code/Common/otbObjectList.h @@ -110,12 +110,15 @@ class ObjectList void Clear(void); class ConstIterator; + class ReverseConstIterator; + /** \class Iterator * \brief Iterator of the object list. */ class Iterator { public: + friend class ObjectList; friend class ConstIterator; /** typedef of the internal iterator */ typedef typename InternalContainerType::iterator InternalIteratorType; @@ -136,6 +139,15 @@ class ObjectList * Decrement. */ Iterator& operator--(); + /** + * Add + */ + Iterator& operator+(int i); + + /** + * Remove + */ + Iterator& operator-(int i); /** * Difference comparison operator. */ @@ -152,7 +164,6 @@ class ObjectList * Copy operator. */ Iterator(const Iterator &it); - private: // Internal iterator. InternalIteratorType m_Iter; @@ -211,8 +222,6 @@ class ObjectList // Internal iterator. InternalConstIteratorType m_Iter; }; - - class ReverseConstIterator; /** \class ReverseIterator * \brief ReverseIterator of the object list. */ @@ -354,7 +363,13 @@ class ObjectList * \return The iterator. */ ReverseConstIterator ReverseEnd(void) const; - + /** + * Erase elements from begin to last. + * \param begin Iterator pointing on first object to erase. + * \param end Iterator pointing past the last object to erase. + */ + void Erase(Iterator begin, Iterator end); + protected: /** Constructor */ ObjectList(); diff --git a/Code/Common/otbObjectList.txx b/Code/Common/otbObjectList.txx index ee5460ac97..0bf954b6cd 100644 --- a/Code/Common/otbObjectList.txx +++ b/Code/Common/otbObjectList.txx @@ -197,6 +197,28 @@ namespace otb { --m_Iter; return *this; + } + /** + * Add + */ + template <class TObject> + typename ObjectList<TObject>::Iterator& + ObjectList<TObject>::Iterator + ::operator+(int i) + { + m_Iter=m_Iter+i; + return *this; + } + /** + * Remove + */ + template <class TObject> + typename ObjectList<TObject>::Iterator& + ObjectList<TObject>::Iterator + ::operator-(int i) + { + m_Iter=m_Iter-i; + return *this; } /** * Difference comparison operator. @@ -629,6 +651,18 @@ namespace otb ReverseConstIterator iter(m_InternalContainer.rend()); return iter; } + /** + * Erase elements from begin to last. + * \param begin Iterator pointing on first object to erase. + * \param end Iterator pointing past the last object to erase. + */ + template <class TObject> + void + ObjectList<TObject> + ::Erase(Iterator begin, Iterator end) + { + m_InternalContainer.erase(begin.m_Iter,end.m_Iter); + } /**PrintSelf method */ template <class TObject> void diff --git a/Code/Common/otbTestMain.h b/Code/Common/otbTestMain.h index bdfd4aa0d6..f67fb4deaa 100644 --- a/Code/Common/otbTestMain.h +++ b/Code/Common/otbTestMain.h @@ -187,8 +187,8 @@ otbMsgDebugMacro(<<"---------------- DEBUT Controle NON-REGRESION --------- std::vector<char*>::iterator itBaselineFilenames = baseLineFilenamesImage.begin(); std::vector<char*>::iterator itTestFilenames = testFilenamesImage.begin(); // For each couple of baseline and test file, do the comparison - for(;(itBaselineFilenames != baseLineFilenamesImage.begin()) - &&(itTestFilenames != testFilenamesImage.begin()); + for(;(itBaselineFilenames != baseLineFilenamesImage.end()) + &&(itTestFilenames != testFilenamesImage.end()); ++itBaselineFilenames,++itTestFilenames) { char * baselineFilenameImage = (*itBaselineFilenames); diff --git a/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.h b/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.h index 3ea9e445a4..a3a67abf5d 100644 --- a/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.h +++ b/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.h @@ -79,8 +79,6 @@ public: typedef typename InputImageType::ValueType ValueType; typedef typename InputImageType::PixelType PixelType; typedef typename InputImageType::SpacingType SpacingType; - /** Size vector typedefs */ - typedef std::vector<SizeType> SizeVectorType; /** Accessors */ itkSetMacro(NumberOfIterations, int); itkSetMacro(SubSampleScale, float); @@ -91,11 +89,6 @@ public: itkGetConstReferenceMacro(InfFiltre,OutputImageListPointerType); itkGetConstReferenceMacro(SupDeci,OutputImageListPointerType); itkGetConstReferenceMacro(InfDeci,OutputImageListPointerType); - /** - * Get the vector of sizes - * \return The vector of sizes - */ - std::vector<typename TOutputImage::SizeType> GetSize(); protected: /** Constructor */ @@ -121,8 +114,6 @@ protected: OutputImageListPointerType m_SupDeci; /** Inf details from subsampling operations */ OutputImageListPointerType m_InfDeci; - /** Sizes vector */ - SizeVectorType m_Size; }; }// End namespace otb diff --git a/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.txx b/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.txx index a6dfc168cd..88a5fdfd65 100644 --- a/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.txx +++ b/Code/MultiScale/otbMorphologicalPyramidAnalyseFilter.txx @@ -49,18 +49,6 @@ namespace otb template <class TInputImage, class TOutputImage, class TMorphoFilter> MorphologicalPyramidAnalyseFilter<TInputImage,TOutputImage,TMorphoFilter> ::~MorphologicalPyramidAnalyseFilter(){} - - /** - * Get the vector of sizes - * \return The vector of sizes - */ - template <class TInputImage, class TOutputImage, class TMorphoFilter> - std::vector<typename TOutputImage::SizeType> - MorphologicalPyramidAnalyseFilter<TInputImage,TOutputImage,TMorphoFilter> - ::GetSize(void) - { - return m_Size; - } /** * Main computation method */ @@ -98,7 +86,7 @@ namespace otb typename SubtractFilterType::Pointer subtract1,subtract2,subtract3,subtract4; typename ResamplerType::Pointer resampler1, resampler2; - // Size vector declaration + // Size declaration typename InputImageType::SizeType size; // local variables declarations and initialisations @@ -142,10 +130,9 @@ namespace otb otbMsgDebugMacro(<<"MorphologicalPyramidAnalyseFilter: subtract2 OK "<<subtract2->GetOutput()->GetLargestPossibleRegion().GetSize()); m_InfFiltre->PushBack(subtract2->GetOutput()); otbMsgDebugMacro("MorphologicalPyramidAnalyseFilter: step "<<i<<" - Image appended to m_InfFiltre"); - // New Size/Spacing computation + + // New Size size = morphoFilter->GetOutput()->GetLargestPossibleRegion().GetSize(); - m_Size.push_back(size); - otbMsgDebugMacro(<<"New size and spacing :"); for (int j =0; j<InputImageType::ImageDimension;j++) { sizeTmp=size[j]; @@ -160,17 +147,15 @@ namespace otb resampler1->SetSize(size); resampler1->Update(); currentImage=resampler1->GetOutput(); - //currentImage = ResampleImage(morphoFilter->GetOutput(),size,spacing); otbMsgDebugMacro(<<"MorphologicalPyramidAnalyseFilter: DownSampling OK "<<currentImage->GetLargestPossibleRegion().GetSize()); // New current image is appeneded to the output list OutputImageList->PushBack(currentImage); // Image upsampling - //upsampled = ResampleImage(currentImage,m_Size.back(),m_Spacing.back()); resampler2 = ResamplerType::New(); resampler2->SetInput(resampler1->GetOutput()); - resampler2->SetSize(m_Size.back()); + resampler2->SetSize(morphoFilter->GetOutput()->GetLargestPossibleRegion().GetSize()); resampler2->Update(); otbMsgDebugMacro(<<"MorphologicalPyramidAnalyseFilter: UpSampling OK "<<resampler2->GetOutput()->GetLargestPossibleRegion().GetSize()); diff --git a/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.h b/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.h new file mode 100644 index 0000000000..55f3bbc52a --- /dev/null +++ b/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.h @@ -0,0 +1,108 @@ +/*========================================================================= + +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 _otbMorphologicalPyramidMRToMSConverter_h +#define _otbMorphologicalPyramidMRToMSConverter_h + +#include "otbImageListToImageListFilter.h" + +namespace otb +{ + namespace morphologicalPyramid + { + /** + * \class MRToMSConverter + * \brief This class convert a multi resolution decomposition from the morphological pyramid to a multi-scale one. + * + * This class convert a multi resolution decomposition from the morphological pyramid to a multi-scale one. + * + * The operation consists in iterativly upsampling and adding decimation details to a given detail image. + * + * \sa MorphologicalPyramidAnalyseFilter + * \sa MorphologicalPyramidSynthesisFilter + */ + template <class TInputImage, class TOutputImage> + class MRToMSConverter + : public ImageListToImageListFilter<TInputImage,TOutputImage> + { + public : + /** Standard typedefs */ + typedef MRToMSConverter Self; + typedef ImageListToImageListFilter<TInputImage,TOutputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + /** Creation through object factory macro */ + itkNewMacro(Self); + /** Type macro */ + itkTypeMacro(MRToMSConverter,ImageListToImageListFilter); + /** Input parameters typedefs */ + typedef TInputImage InputImageType; + typedef typename Superclass::InputImagePointer InputImagePointer; + typedef typename Superclass::InputImageListPointerType InputImageListPointerType; + /** Output parameters typedefs */ + typedef TOutputImage OutputImageType; + typedef typename Superclass::OutputImagePointer OutputImagePointerType; + typedef typename Superclass::OutputImageListType OutputImageListType; + typedef typename Superclass::OutputImageListPointerType OutputImageListPointerType; + /** Input image lists setters */ + itkSetMacro(SupFiltre,InputImageListPointerType); + itkSetMacro(InfFiltre,InputImageListPointerType); + itkSetMacro(SupDeci,InputImageListPointerType); + itkSetMacro(InfDeci,InputImageListPointerType); + + /** Number of iterations accessors */ + itkSetMacro(NumberOfIterations, unsigned int); + itkGetMacro(NumberOfIterations, unsigned int); + + /** Full resolution detail image lists getters */ + itkGetMacro(SupFiltreFullResolution,OutputImageListPointerType); + itkGetMacro(InfFiltreFullResolution,OutputImageListPointerType); + protected: + /** Constructor */ + MRToMSConverter(); + /** Destructor */ + ~MRToMSConverter() {}; + + /** Main computation method */ + void GenerateData(); + /** PrintSelf method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + private : + MRToMSConverter(const Self&); // purposely not implemented + void operator=(const Self&); // purposely not implemented + + InputImageListPointerType m_SupFiltre; + InputImageListPointerType m_InfFiltre; + InputImageListPointerType m_SupDeci; + InputImageListPointerType m_InfDeci; + OutputImageListPointerType m_SupFiltreFullResolution; + OutputImageListPointerType m_InfFiltreFullResolution; + unsigned int m_NumberOfIterations; + + + + + }; + } // End namespace morphologicalPyramid +}// End namespace otb + +#ifndef ITK_MANUAL_INSTANTIATION +#include "otbMorphologicalPyramidMRToMSConverter.txx" +#endif + +#endif diff --git a/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.txx b/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.txx new file mode 100644 index 0000000000..15847087be --- /dev/null +++ b/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.txx @@ -0,0 +1,93 @@ +/*========================================================================= + +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 __otbMorphologicalPyramidMRToMSConverter_txx +#define __otbMorphologicalPyramidMRToMSConverter_txx + +#include "otbMorphologicalPyramidMRToMSConverter.h" +#include "otbMorphologicalPyramidResampler.h" +#include "otbMacro.h" + +namespace otb +{ + namespace morphologicalPyramid + { + /** + * Constructor + */ + template <class TInputImage,class TOuputImage> + MRToMSConverter<TInputImage, TOuputImage> + ::MRToMSConverter() + { + m_InfFiltreFullResolution = OutputImageListType::New(); + m_SupFiltreFullResolution = OutputImageListType::New(); + m_NumberOfIterations = 0; + } + /** + * Main computation method + */ + template <class TInputImage,class TOuputImage> + void + MRToMSConverter<TInputImage, TOuputImage> + ::GenerateData() + { + // typedef of the resampling filter + typedef otb::morphologicalPyramid::Resampler<InputImageType,OutputImageType> ResamplerType; + + // Definition of the resampler filters + typename ResamplerType::Pointer resampler; + + // Full resolution size + typename InputImageType::SizeType frsize = m_SupFiltre->Front()->GetLargestPossibleRegion().GetSize(); + otbMsgDebugMacro(<<"Full resolution size: "<<frsize); + + /// Full resolution details reconstruction + for(int i=0; i<m_NumberOfIterations; i++) + { + resampler = ResamplerType::New(); + resampler->SetSize(frsize); + resampler->SetInput(m_SupFiltre->GetNthElement(i)); + resampler->Update(); + m_SupFiltreFullResolution->PushBack(resampler->GetOutput()); + otbMsgDebugMacro(<<"SupFiltre Details reconstruction level "<<i<<" OK"); + resampler = ResamplerType::New(); + resampler->SetSize(frsize); + resampler->SetInput(m_InfFiltre->GetNthElement(i)); + resampler->Update(); + m_InfFiltreFullResolution->PushBack(resampler->GetOutput()); + otbMsgDebugMacro(<<"InfFiltre Details reconstruction level "<<i<<" OK"); + resampler = ResamplerType::New(); + resampler->SetSize(frsize); + resampler->SetInput(this->GetInput()->GetNthElement(i)); + resampler->Update(); + this->GetOutput()->PushBack(resampler->GetOutput()); + otbMsgDebugMacro(<<"Analyse Details reconstruction level "<<i<<" OK"); + } + } + /** + * PrintSelf method + */ + template <class TInputImage,class TOuputImage> + void + MRToMSConverter<TInputImage, TOuputImage> + ::PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + } // End namespace morphologicalPyramid +} // End namespace otb +#endif diff --git a/Code/MultiScale/otbMorphologicalPyramidResampler.h b/Code/MultiScale/otbMorphologicalPyramidResampler.h index 89258bedc3..026f1871a7 100644 --- a/Code/MultiScale/otbMorphologicalPyramidResampler.h +++ b/Code/MultiScale/otbMorphologicalPyramidResampler.h @@ -53,7 +53,7 @@ namespace otb /** Creation through object factory macro */ itkNewMacro(Self); /** Type macro */ - itkTypeMacro(MorphologicalPyramidResampler,ImageToImageFilter); + itkTypeMacro(Resampler,ImageToImageFilter); /** Template parameters typedefs */ typedef TInputImage InputImageType; typedef TOutputImage OutputImageType; diff --git a/Code/MultiScale/otbMorphologicalPyramidResampler.txx b/Code/MultiScale/otbMorphologicalPyramidResampler.txx index 720cd92349..b0de89ebd5 100644 --- a/Code/MultiScale/otbMorphologicalPyramidResampler.txx +++ b/Code/MultiScale/otbMorphologicalPyramidResampler.txx @@ -134,8 +134,8 @@ Resampler<TInputImage, TOuputImage> typename TransformType::ParametersType scales(2); typename InputImageType::SizeType inputSize = this->GetInput()->GetLargestPossibleRegion().GetSize(); typename InputImageType::SpacingType inputSpacing = this->GetInput()->GetSpacing(); - scales[0]=static_cast<double>(inputSize[0])/static_cast<double>(m_Size[0]); - scales[1]=static_cast<double>(inputSize[1])/static_cast<double>(m_Size[1]); + scales[0]=static_cast<double>(inputSize[0]-1)/static_cast<double>(m_Size[0]-1); + scales[1]=static_cast<double>(inputSize[1]-1)/static_cast<double>(m_Size[1]-1); transform->SetParameters(scales); // Resampling filter set up @@ -156,64 +156,6 @@ Resampler<TInputImage, TOuputImage> resampler->Update(); result = resampler->GetOutput(); - // // variable definition for the following cases -// typename OutputImageType::RegionType::IndexType inputStart; -// typename OutputImageType::RegionType::IndexType outputStart; -// typename OutputImageType::RegionType::SizeType size; -// typename OutputImageType::RegionType inputRegion; -// typename OutputImageType::RegionType outputRegion; - -// // Gestion d'un cas particulier qui fait apparaître une bande -// // noire sur un des bords de l'image -// // Dans ce cas on duplique la dernière ligne de l'image -// if(m_Spacing[0]*static_cast<float>(m_Size[0]-1)>=(this->GetInput()->GetSpacing()[0]*static_cast<float>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]-1))) -// { -// inputStart[0]=m_Size[0]-2; -// inputStart[1]=0; -// outputStart[0]=m_Size[0]-1; -// outputStart[1]=0; -// size[0]=1; -// size[1]=m_Size[1]; -// inputRegion.SetSize(size); -// outputRegion.SetSize(size); -// inputRegion.SetIndex(inputStart); -// outputRegion.SetIndex(outputStart); -// ConstIteratorType inputIt(result, inputRegion); -// IteratorType outputIt(result,outputRegion); -// // Duplication de la dernière ligne -// for(inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd();++inputIt,++outputIt) -// { -// outputIt.Set(inputIt.Get()); -// } -// } -// // Gestion d'un cas particulier qui fait apparaître une bande -// // noire sur un des bords de l'image -// // Dans ce cas on duplique la dernière colonne de l'image -// if(m_Spacing[1]*static_cast<float>(m_Size[1]-1)>=(this->GetInput()->GetSpacing()[1]*static_cast<float>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]-1))) -// { -// typename OutputImageType::RegionType::IndexType inputStart; -// typename OutputImageType::RegionType::IndexType outputStart; -// typename OutputImageType::RegionType::SizeType size; -// typename OutputImageType::RegionType inputRegion; -// typename OutputImageType::RegionType outputRegion; -// inputStart[1]=m_Size[1]-2; -// inputStart[0]=0; -// outputStart[1]=m_Size[1]-1; -// outputStart[0]=0; -// size[1]=1; -// size[0]=m_Size[0]; -// inputRegion.SetSize(size); -// outputRegion.SetSize(size); -// inputRegion.SetIndex(inputStart); -// outputRegion.SetIndex(outputStart); -// ConstIteratorType inputIt(result, inputRegion); -// IteratorType outputIt(result,outputRegion); -// // Duplication de la dernière colonne -// for(inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd();++inputIt,++outputIt) -// { -// outputIt.Set(inputIt.Get()); -// } -// } /** Output filter connexion */ this->GraftOutput(result); } diff --git a/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.h b/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.h index 566a520dc6..a6be0dc713 100644 --- a/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.h +++ b/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.h @@ -81,11 +81,6 @@ public: itkSetMacro(InfFiltre,OutputImageListPointerType); itkSetMacro(SupDeci,OutputImageListPointerType); itkSetMacro(InfDeci,OutputImageListPointerType); - /** - * Set the vector of sizes - * \param size The vector of sizes - */ - virtual void SetSize(std::vector<typename TOutputImage::SizeType> size); protected: /** Constructor */ @@ -105,8 +100,6 @@ protected: OutputImageListPointerType m_SupDeci; /** Inf details from subsampling operations */ OutputImageListPointerType m_InfDeci; - /** Sizes vector */ - SizeVectorType m_Size; }; }// End namespace otb diff --git a/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.txx b/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.txx index 673231e183..89f937070a 100644 --- a/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.txx +++ b/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.txx @@ -24,6 +24,7 @@ PURPOSE. See the above copyright notices for more information. #include "itkSubtractImageFilter.h" #include "itkAddImageFilter.h" #include "itkImageDuplicator.h" +#include "otbMacro.h" namespace otb { @@ -39,17 +40,6 @@ MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> template <class TInputImage, class TOutputImage> MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> ::~MorphologicalPyramidSynthesisFilter() {} -/** - * Get the vector of sizes - * \param size The vector of sizes - */ -template <class TInputImage, class TOutputImage> -void -MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> -::SetSize(std::vector<typename TOutputImage::SizeType> size) -{ - m_Size=size; -} /** * Main computation method */ @@ -58,6 +48,7 @@ void MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> ::GenerateData(void) { + otbMsgDebugMacro(<<"MorphologicalPyramidSynthesisFilter : Entering main method."); // Input image pointer OutputImageListType * OutputImageList = this->GetOutput(); // typedefs of the filters @@ -79,13 +70,27 @@ MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> typename SubtractFilterType::Pointer subtract1,subtract2; typename ResamplerType::Pointer resampler; + + // Size vector computation + SizeVectorType size; + + ImageListIterator it = m_SupFiltre->Begin(); + + while(it!=m_SupFiltre->End()) + { + size.push_back(it.Get()->GetLargestPossibleRegion().GetSize()); + ++it; + } + otbMsgDebugMacro(<<"MorphologicalPyramidSynthesisFilter : Size vector computation OK"); + // Iterators definition ImageListReverseIterator itInfFiltre = m_InfFiltre->ReverseBegin(); ImageListReverseIterator itSupFiltre = m_SupFiltre->ReverseBegin(); ImageListReverseIterator itInfDeci = m_InfDeci->ReverseBegin(); ImageListReverseIterator itSupDeci = m_SupDeci->ReverseBegin(); - SizeReverseIterator itSize = m_Size.rbegin(); + SizeReverseIterator itSize = size.rbegin(); + int i =1; //--------------------------------------------------------// // Main loop // //--------------------------------------------------------// @@ -93,14 +98,16 @@ MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> && itSupFiltre!=m_SupFiltre->ReverseEnd() && itInfDeci!=m_InfDeci->ReverseEnd() && itSupDeci!=m_SupDeci->ReverseEnd() - && itSize!=m_Size.rend()) + && itSize!=size.rend()) { - + + ++i; // Upsampling current image resampler = ResamplerType::New(); resampler->SetSize(*itSize); resampler->SetInput(currentImage); - + resampler->Update(); + otbMsgDebugMacro(<<"MorphologicalPyramidSynthesisFilter: step "<<i<<" Upsampling OK"); // Adding *Sup details from current level add1= AddFilterType::New(); add1->SetInput1(resampler->GetOutput()); @@ -117,6 +124,8 @@ MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> subtract2->SetInput1(subtract1->GetOutput()); subtract2->SetInput2(itInfDeci.Get()); subtract2->Update(); + otbMsgDebugMacro(<<"MorphologicalPyramidSynthesisFilter: step "<<i<<" Details addition OK"); + // Updating current image currentImage=subtract2->GetOutput(); @@ -129,6 +138,7 @@ MorphologicalPyramidSynthesisFilter<TInputImage,TOutputImage> ++itInfDeci; ++itSize; } + otbMsgDebugMacro(<<"MorphologicalPyramidSynthesisFilter: Exiting main method."); } /** * PrintSelf method diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index 3e7368592c..0737eace72 100644 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -261,6 +261,11 @@ ADD_TEST(coTuImageListSourceNew ${COMMON_TESTS} ADD_TEST(coTuImageToImageListFilterNew ${COMMON_TESTS} otbImageToImageListFilterNew) +# ------- otb::ImageListToImageListFilter ------------------------------------------- + +ADD_TEST(coTvImageListToImageListFilterNew ${COMMON_TESTS} + otbImageListToImageListFilterNew) + # ------- Fichiers sources CXX ----------------------------------- SET(BasicCommon_SRCS @@ -292,6 +297,7 @@ otbImageListNew.cxx otbImageList.cxx otbImageListSourceNew.cxx otbImageToImageListFilterNew.cxx +otbImageListToImageListFilterNew.cxx ) diff --git a/Testing/Code/Common/otbCommonTests.cxx b/Testing/Code/Common/otbCommonTests.cxx index 61685ae80a..c497e6dbbc 100644 --- a/Testing/Code/Common/otbCommonTests.cxx +++ b/Testing/Code/Common/otbCommonTests.cxx @@ -54,4 +54,5 @@ REGISTER_TEST(otbImageListNew); REGISTER_TEST(otbImageList); REGISTER_TEST(otbImageListSourceNew); REGISTER_TEST(otbImageToImageListFilterNew); +REGISTER_TEST(otbImageListToImageListFilterNew); } diff --git a/Testing/Code/Common/otbObjectList.cxx b/Testing/Code/Common/otbObjectList.cxx index 8eaefa5728..00861204dc 100644 --- a/Testing/Code/Common/otbObjectList.cxx +++ b/Testing/Code/Common/otbObjectList.cxx @@ -222,6 +222,25 @@ int otbObjectList(int argc, char * argv[]) { fail("Clear()"); } + + + // Testing erase with iterators + imageList->PushBack(reader1->GetOutput()); + imageList->PushBack(reader2->GetOutput()); + imageList->PushBack(reader3->GetOutput()); + + ImageListType::Iterator begin = imageList->Begin()+1; + ImageListType::Iterator end = imageList->End(); + imageList->Erase(begin,end); + + if(imageList->Size()!=1) + { + fail("Erase(Iterator,Iterator)/Size()"); + } + if(imageList->Back()!=reader1->GetOutput()) + { + fail("Erase(Iterator,Iterator)/Back()"); + } } catch( itk::ExceptionObject & err ) diff --git a/Testing/Code/MultiScale/CMakeLists.txt b/Testing/Code/MultiScale/CMakeLists.txt index c84441d0b2..04bf371282 100644 --- a/Testing/Code/MultiScale/CMakeLists.txt +++ b/Testing/Code/MultiScale/CMakeLists.txt @@ -15,7 +15,7 @@ SET(TOL 0.0) SET(MULTISCALE_TESTS ${CXX_TEST_PATH}/otbMultiScaleTests) -# ------- otb::MorphologicalPyramidAnalyseFilter ---------- +# ------- otb::MorphologicalPyramidResampler ---------- ADD_TEST(msTuMorphoPyrResamplerNew ${MULTISCALE_TESTS} otbMorphologicalPyramidResamplerNew) @@ -32,8 +32,6 @@ ADD_TEST(msTvMorphoPyrResampler ${MULTISCALE_TESTS} ${TEMP}/msPyrResampler_IKO_LesHalles_full.tif 256 256 -# 2.0 -# 2.0 ) # ------- otb::MorphologicalPyramidAnalyseFilter ---------- @@ -60,7 +58,7 @@ ADD_TEST(msTvMorphoPyrAnalyseFilter ${MULTISCALE_TESTS} 2 2.0) -# ------- otb::MorphologicalPyramidAnalyseFilter ---------- +# ------- otb::MorphologicalPyramidSynthesisFilter ---------- ADD_TEST(msTuMorphoPyrSynthesisFilterNew ${MULTISCALE_TESTS} otbMorphologicalPyramidSynthesisFilterNew) @@ -75,6 +73,28 @@ ADD_TEST(msTvMorphoPyrSynthesisFilter ${MULTISCALE_TESTS} 4 2.0) +# ------- otb::MorphologicalPyramidMRToMSConverter ---------- + +ADD_TEST(msTuMorphoPyrMRToMSConverterNew ${MULTISCALE_TESTS} + otbMorphologicalPyramidMRToMSConverterNew) + +ADD_TEST(msTvMorphoPyrMRToMSConverter ${MULTISCALE_TESTS} + --compare-n-images ${TOL} 3 + ${BASELINE}/msPyrMRToMS_IKO_Halles_4_2_sf_full.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_sf_full.tif + ${BASELINE}/msPyrMRToMS_IKO_Halles_4_2_if_full.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_if_full.tif + ${BASELINE}/msPyrMRToMS_IKO_Halles_4_2_an_full.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_an_full.tif + + otbMorphologicalPyramidMRToMSConverter + ${INPUTDATA}/ROI_IKO_PAN_LesHalles.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_sf_full.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_if_full.tif + ${TEMP}/msPyrMRToMS_IKO_Halles_4_2_an_full.tif + 4 + 2.0) + # ------- Fichiers sources CXX ----------------------------------- SET(BasicMultiScale_SRCS otbMorphologicalPyramidResamplerNew.cxx @@ -83,6 +103,8 @@ otbMorphologicalPyramidAnalyseFilterNew.cxx otbMorphologicalPyramidAnalyseFilter.cxx otbMorphologicalPyramidSynthesisFilterNew.cxx otbMorphologicalPyramidSynthesisFilter.cxx +otbMorphologicalPyramidMRToMSConverterNew.cxx +otbMorphologicalPyramidMRToMSConverter.cxx ) diff --git a/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.cxx b/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.cxx new file mode 100644 index 0000000000..0a06fc0289 --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverter.cxx @@ -0,0 +1,109 @@ +/*========================================================================= + +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 "otbMorphologicalPyramidAnalyseFilter.h" +#include "otbMorphologicalPyramidMRToMSConverter.h" +#include "otbOpeningClosingMorphologicalFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbImage.h" + +int otbMorphologicalPyramidMRToMSConverter(int argc, char * argv[]) +{ + try + { + const char * inputFilename = argv[1]; + const char * outputFilename1 = argv[2]; + const char * outputFilename2 = argv[3]; + const char * outputFilename3 = argv[4]; + const unsigned int numberOfIterations = atoi(argv[5]); + const float subSampleScale = atof(argv[6]); + + const unsigned int Dimension = 2; + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType; + typedef otb::OpeningClosingMorphologicalFilter<InputImageType,InputImageType,StructuringElementType> + OpeningClosingFilterType; + typedef otb::MorphologicalPyramidAnalyseFilter<InputImageType,InputImageType,OpeningClosingFilterType> + PyramidAnalyseFilterType; + typedef otb::morphologicalPyramid::MRToMSConverter<InputImageType,OutputImageType> MRToMSConverterType; + + + // Reading input image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(inputFilename); + + // Analysis + PyramidAnalyseFilterType::Pointer pyramidAnalyse = PyramidAnalyseFilterType::New(); + pyramidAnalyse->SetNumberOfIterations(numberOfIterations); + pyramidAnalyse->SetSubSampleScale(subSampleScale); + pyramidAnalyse->SetInput(reader->GetOutput()); + pyramidAnalyse->Update(); + + // From multi resolution to multi scale + MRToMSConverterType::Pointer mrtoms = MRToMSConverterType::New(); + mrtoms->SetInput(pyramidAnalyse->GetOutput()); + mrtoms->SetNumberOfIterations(numberOfIterations); + mrtoms->SetSupFiltre(pyramidAnalyse->GetSupFiltre()); + mrtoms->SetSupDeci(pyramidAnalyse->GetSupDeci()); + mrtoms->SetInfFiltre(pyramidAnalyse->GetInfFiltre()); + mrtoms->SetInfDeci(pyramidAnalyse->GetInfDeci()); + mrtoms->Update(); + + // Writing the output images + WriterType::Pointer writer1 = WriterType::New(); + writer1->SetFileName(outputFilename1); + writer1->SetInput(mrtoms->GetSupFiltreFullResolution()->Back()); + writer1->Update(); + + WriterType::Pointer writer2 = WriterType::New(); + writer2->SetFileName(outputFilename2); + writer2->SetInput(mrtoms->GetInfFiltreFullResolution()->Back()); + writer2->Update(); + + WriterType::Pointer writer3 = WriterType::New(); + writer3->SetFileName(outputFilename3); + writer3->SetInput(mrtoms->GetOutput()->Back()); + writer3->Update(); + + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; + } diff --git a/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverterNew.cxx b/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverterNew.cxx new file mode 100644 index 0000000000..6f1eaf073b --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalPyramidMRToMSConverterNew.cxx @@ -0,0 +1,54 @@ +/*========================================================================= + +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 "otbMorphologicalPyramidMRToMSConverter.h" +#include "otbImage.h" + +int otbMorphologicalPyramidMRToMSConverterNew(int argc, char * argv[]) +{ + try + { + const unsigned int Dimension = 2; + typedef unsigned char InputPixelType; + typedef unsigned char OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + typedef otb::morphologicalPyramid::MRToMSConverter<InputImageType,OutputImageType> MRToMSConverterType; + + + // Instantiation + MRToMSConverterType::Pointer mrtoms = MRToMSConverterType::New(); + + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; + } diff --git a/Testing/Code/MultiScale/otbMorphologicalPyramidResampler.cxx b/Testing/Code/MultiScale/otbMorphologicalPyramidResampler.cxx index 52306d904a..5120f6184a 100644 --- a/Testing/Code/MultiScale/otbMorphologicalPyramidResampler.cxx +++ b/Testing/Code/MultiScale/otbMorphologicalPyramidResampler.cxx @@ -30,8 +30,6 @@ int otbMorphologicalPyramidResampler(int argc, char * argv[]) const char* outputFilename2 = argv[3]; const unsigned int size_x = atoi(argv[4]); const unsigned int size_y = atoi(argv[5]); - // const float spacing_x = atof(argv[5]); -// const float spacing_y = atof(argv[6]); const unsigned int Dimension = 2; typedef unsigned char InputPixelType; @@ -54,15 +52,10 @@ int otbMorphologicalPyramidResampler(int argc, char * argv[]) size[0] = size_x; size[1] = size_y; - // InputImageType::SpacingType spacing; -// spacing[0] = spacing_x; -// spacing[1] = spacing_y; - // Instantiation ResamplerType::Pointer resampler = ResamplerType::New(); resampler->SetInput(reader->GetOutput()); resampler->SetSize(size); - // resampler->SetSpacing(spacing); // File writing WriterType::Pointer writer = WriterType::New(); diff --git a/Testing/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.cxx b/Testing/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.cxx index 347c7e3e08..872bcf4528 100644 --- a/Testing/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.cxx +++ b/Testing/Code/MultiScale/otbMorphologicalPyramidSynthesisFilter.cxx @@ -70,6 +70,14 @@ int otbMorphologicalPyramidSynthesisFilter(int argc, char * argv[]) pyramidSynthesis->SetSupDeci(pyramidAnalyse->GetSupDeci()); pyramidSynthesis->SetInfFiltre(pyramidAnalyse->GetInfFiltre()); pyramidSynthesis->SetInfDeci(pyramidAnalyse->GetInfDeci()); + pyramidSynthesis->Update(); + + // Writing the output image + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outputFilename); + writer->SetInput(pyramidSynthesis->GetOutput()->Back()); + writer->Update(); + } catch( itk::ExceptionObject & err ) { diff --git a/Testing/Code/MultiScale/otbMultiScaleTests.cxx b/Testing/Code/MultiScale/otbMultiScaleTests.cxx index b023e1aec3..2333ee854d 100644 --- a/Testing/Code/MultiScale/otbMultiScaleTests.cxx +++ b/Testing/Code/MultiScale/otbMultiScaleTests.cxx @@ -32,4 +32,6 @@ REGISTER_TEST(otbMorphologicalPyramidAnalyseFilterNew); REGISTER_TEST(otbMorphologicalPyramidAnalyseFilter); REGISTER_TEST(otbMorphologicalPyramidSynthesisFilterNew); REGISTER_TEST(otbMorphologicalPyramidSynthesisFilter); +REGISTER_TEST(otbMorphologicalPyramidMRToMSConverterNew); +REGISTER_TEST(otbMorphologicalPyramidMRToMSConverter); } -- GitLab