From 960d1369849baba8f4d069c3eeb4dd875442fff4 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@c-s.fr> Date: Thu, 7 Dec 2006 16:48:52 +0000 Subject: [PATCH] =?UTF-8?q?-=20Nouvelle=20classe=20de=20base=20pour=20les?= =?UTF-8?q?=20traitements=20"Liste=20d'images=20->=20Graphe=20RCC8".=20-?= =?UTF-8?q?=20Squelettes=20et=20test=20unitaire=20du=20filtre=20de=20calcu?= =?UTF-8?q?l=20du=20graphe=20RCC8=20=C3=A0=20partir=20d'une=20liste=20d'im?= =?UTF-8?q?ages=20de=20segmentation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../otbImageListToRCC8GraphFilter.h | 82 ++++++++++++++++++ .../otbImageListToRCC8GraphFilter.txx | 76 +++++++++++++++++ ...bImageMultiSegmentationToRCC8GraphFilter.h | 84 +++++++++++++++++++ ...mageMultiSegmentationToRCC8GraphFilter.txx | 58 +++++++++++++ Testing/Code/SpatialReasoning/CMakeLists.txt | 31 ++++++- .../otbImageListToRCC8GraphFilterNew.cxx | 29 +------ ...mageMultiSegmentationToRCC8GraphFilter.cxx | 80 ++++++++++++++++++ ...eMultiSegmentationToRCC8GraphFilterNew.cxx | 52 ++++++++++++ .../otbSpatialReasoningTests.cxx | 4 +- 9 files changed, 467 insertions(+), 29 deletions(-) create mode 100644 Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h create mode 100644 Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx create mode 100644 Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h create mode 100644 Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx create mode 100644 Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx create mode 100644 Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx diff --git a/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h new file mode 100644 index 0000000000..cfe1350e0a --- /dev/null +++ b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.h @@ -0,0 +1,82 @@ +/*========================================================================= + +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 _otbImageListToRCC8GraphFilter_h +#define _otbImageListToRCC8GraphFilter_h + +#include "otbRCC8GraphSource.h" + +namespace otb +{ +/** \class ImageListToRCC8GraphFilter + * \brief Base class for filters taking an images list as input to + * produce a RCC8 graph. + */ +template <class TInputImage, class TOutputGraph> +class ImageListToRCC8GraphFilter + : public RCC8GraphSource<TOutputGraph> +{ +public: + /** Standard typedefs */ + typedef ImageListToRCC8GraphFilter Self; + typedef RCC8GraphSource<TOutputGraph> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + /** Type macro */ + itkNewMacro(Self); + /** Creation through object factory macro */ + itkTypeMacro(ImageListToRCC8GraphFilter, RCC8GraphSource); + /** Template input parameters typedefs */ + typedef TInputImage InputImageType; + typedef typename InputImageType::ConstPointer InputImagePointer; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename InputImageType::PixelType InputImagePixelType; + typedef typename InputImageType::SizeType SizeType; + typedef typename InputImageType::ValueType ValueType; + typedef ImageList<InputImageType> InputImageListType; + typedef typename InputImageListType::Pointer InputImageListPointerType; + typedef typename InputImageListType::ConstPointer InputImageListConstPointer; + /** Template output parameters typedefs */ + typedef TOutputGraph OutputGraphType; + typedef typename Superclass::OutputGraphPointerType OutputGraphPointerType; + typedef typename OutputGraphType::VertexType VertexType; + typedef typename VertexType::Pointer VertexPointerType; + typedef typename OutputGraphType::RCC8ValueType RCC8ValueType; + /** InputImage dimension constant */ + itkStaticConstMacro(InputImageDimension, unsigned int,TInputImage::ImageDimension); + /** Overiding the SetInput() and GetInput() methods */ + virtual void SetInput( const InputImageListType * imageList); + virtual InputImageListType * GetInput(void); + +protected: + /** Constructor */ + ImageListToRCC8GraphFilter(); + /** Destructor */ + virtual ~ImageListToRCC8GraphFilter() {}; + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageListToRCC8GraphFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; +}// End namespace otb +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageListToRCC8GraphFilter.txx" +#endif + +#endif diff --git a/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx new file mode 100644 index 0000000000..534e9da636 --- /dev/null +++ b/Code/SpatialReasoning/otbImageListToRCC8GraphFilter.txx @@ -0,0 +1,76 @@ +/*========================================================================= + +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 _otbImageListToRCC8GraphFilter_txx +#define _otbImageListToRCC8GraphFilter_txx + +#include "otbImageListToRCC8GraphFilter.h" + +namespace otb +{ +/** + * Constructor + */ +template <class TInputImage, class TOutputGraph> +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::ImageListToRCC8GraphFilter() +{ + this->SetNumberOfRequiredInputs(1); +} +/** + * Input Connection + * \param image The input image. + */ +template <class TInputImage, class TOutputGraph> +void +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::SetInput(const InputImageListType *imageList) +{ + // A single input image + this->itk::ProcessObject::SetNthInput(0,const_cast<InputImageListType*>(imageList)); +} +/** + * Input image retrieval + * \return The input image. + */ +template <class TInputImage, class TOutputGraph> +typename ImageListToRCC8GraphFilter<TInputImage,TOutputGraph>::InputImageListType * +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::GetInput(void) +{ + // If there is no input + if (this->GetNumberOfInputs()<1) + { + // exit + return 0; + } + // else return the first input + return static_cast<InputImageListType * > + (this->itk::ProcessObject::GetInput(0) ); +} +/** + * PrintSelf Method + */ +template <class TInputImage, class TOutputGraph> +void +ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} +} // End namespace otb +#endif diff --git a/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h new file mode 100644 index 0000000000..d63618545b --- /dev/null +++ b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.h @@ -0,0 +1,84 @@ +/*========================================================================= + + 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 _otbImageMultiSegmentationToRCC8GraphFilter_h +#define _otbImageMultiSegmentationToRCC8GraphFilter_h + +#include "otbImageListToRCC8GraphFilter.h" + +namespace otb +{ +/** + * \class ImageMultiSegmentationToRCC8GraphFilter + * \brief This class takes a list of labelled segmentation images + * and build the RCC8 graph of the set of regions it represents. + */ +template <class TInputImage, class TOutputGraph> +class ImageMultiSegmentationToRCC8GraphFilter + : public ImageListToRCC8GraphFilter<TInputImage,TOutputGraph> +{ +public: + /** Standard class typedefs. */ + typedef ImageMultiSegmentationToRCC8GraphFilter Self; + typedef ImageListToRCC8GraphFilter<TInputImage, TOutputGraph> 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(ImageMultiSegmentationToRCC8GraphFilter,ImageListToRCC8GraphFilter); + /** Input related typedefs */ + typedef TInputImage InputImageType; + typedef typename InputImageType::Pointer InputImagePointerType; + /** Output related typedefs */ + typedef TOutputGraph OutputGraphType; + typedef typename OutputGraphType::Pointer OutputGraphPointerType; + typedef typename OutputGraphType::VertexType VertexType; + typedef typename VertexType::Pointer VertexPointerType; + +/* /// Get The statistics for the different relations */ +/* itkGetConstMacro(TotalNumberOfRegions,int); */ +/* itkGetConstMacro(NumberOfRelations,int); */ +/* /// Get the number of regions by segmentation image */ +/* std::vector<int> GetNumberOfRegions(void); */ +/* /// Set a filter to not take in account relations whose index is */ +/* /// under the threshold */ +/* itkGetConstMacro(RelationFilter,int); */ +/* itkSetMacro(RelationFilter,int); */ + +protected: + /** Constructor */ + ImageMultiSegmentationToRCC8GraphFilter(); + /** Destructor */ + ~ImageMultiSegmentationToRCC8GraphFilter(); + /** Main computation method */ + virtual void GenerateData(); + /** PrintSelf method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + /* int m_NumberOfRelations; */ +/* int m_TotalNumberOfRegions; */ +/* std::vector<unsigned int> m_NumberOfRegions; */ +}; +} // End namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageMultiSegmentationToRCC8GraphFilter.txx" +#endif + +#endif diff --git a/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx new file mode 100644 index 0000000000..87901e3696 --- /dev/null +++ b/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.txx @@ -0,0 +1,58 @@ +/*========================================================================= + + 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 _otbImageMultiSegmentationToRCC8GraphFilter_txx +#define _otbImageMultiSegmentationToRCC8GraphFilter_txx + +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" +#include "itkMinimumMaximumImageFilter.h" +#include "otbImageToImageRCC8Calculator.h" + +namespace otb +{ +/** + * Constructor. + */ +template <class TInputImage, class TOutputGraph> +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::ImageMultiSegmentationToRCC8GraphFilter() +{} +/** + * Destructor. + */ +template <class TInputImage, class TOutputGraph> +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::~ImageMultiSegmentationToRCC8GraphFilter() +{} +/** + * Main computation method. + */ +template <class TInputImage, class TOutputGraph> +void +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::GenerateData() +{} +template <class TInputImage, class TOutputGraph> +void +ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} +} // end namespace otb +#endif + diff --git a/Testing/Code/SpatialReasoning/CMakeLists.txt b/Testing/Code/SpatialReasoning/CMakeLists.txt index 73eee45636..d0a4738441 100644 --- a/Testing/Code/SpatialReasoning/CMakeLists.txt +++ b/Testing/Code/SpatialReasoning/CMakeLists.txt @@ -115,8 +115,31 @@ ADD_TEST(srTvRCC8GraphIOEndToEnd ${SPATIALREASONING_TESTS} # ------- otb::ImageListToRCC8GraphFilter -------------------------- -#ADD_TEST(srTuImageListToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} -# otbImageListToRCC8GraphFilterNew) + + +ADD_TEST(srTuImageListToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} + otbImageListToRCC8GraphFilterNew) + + +# ------- otb::ImageMultiSegmentationToRCC8GraphFilter -------------------------- + +ADD_TEST(srTuMultiSegToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} + otbImageMultiSegmentationToRCC8GraphFilterNew) + + +#ADD_TEST(srTvMultiSegToRCC8GraphFilter ${SPATIALREASONING_TESTS} +# --compare-ascii ${TOL} +# ${BASELINE_FILES}/srRCC8GraphFilterOutput.dot +# ${TEMP}/srRCC8GraphFilterOutput.dot +# otbImageMultiSegmentationToRCC8GraphFilter +# ${TEMP}/srRCC8GraphFilterOutput.dot +# 4 +# ${INPUTDATA}/ +# ${INPUTDATA}/ +# ${INPUTDATA}/ +# ${INPUTDATA}/ +#) + # ------- Fichiers sources CXX ----------------------------------- @@ -137,7 +160,9 @@ otbRCC8GraphFileWriter.cxx otbRCC8GraphFileReaderNew.cxx otbRCC8GraphFileReader.cxx otbRCC8GraphIOEndToEnd.cxx -#otbImageListTORCC8GraphFilterNew.cxx +otbImageListToRCC8GraphFilterNew.cxx +otbImageMultiSegmentationToRCC8GraphFilterNew.cxx +#otbImageMultiSegmentationToRCC8GraphFilter.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx index 886575dfed..f5ab0cadb9 100644 --- a/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx +++ b/Testing/Code/SpatialReasoning/otbImageListToRCC8GraphFilterNew.cxx @@ -17,7 +17,9 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "itkExceptionObject.h" #include "otbRCC8Graph.h" +#include "otbImage.h" #include "otbRCC8VertexBase.h" +#include "otbImageListToRCC8GraphFilter.h" int otbImageListToRCC8GraphFilterNew(int argc, char* argv[]) { @@ -32,7 +34,8 @@ try ImageListToRCC8GraphFilterType; // Instanatiation - ImageListToRCC8GraphFilterType::Pointer filter = ImageListToRCC8GraphFilter::New(); + ImageListToRCC8GraphFilterType::Pointer filter = ImageListToRCC8GraphFilterType::New(); + } catch( itk::ExceptionObject & err ) { @@ -47,27 +50,3 @@ catch( ... ) } return EXIT_SUCCESS; } - - - - - - - - - - - - - - - - - - - - - - - -} diff --git a/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx new file mode 100644 index 0000000000..1330962046 --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilter.cxx @@ -0,0 +1,80 @@ +/*========================================================================= + +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 "otbRCC8Graph.h" +#include "otbImage.h" +#include "otbImageList.h" +#include "otbRCC8VertexBase.h" +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" +#include "otbImageFileReader.h" +#include "otbRCC8GraphFileWriter.h" + +int otbImageMultiSegmentationToRCC8GraphFilter(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + char * outputFilename = argv[1]; + unsigned int nbImages = atoi(argv[2]); + + // typedefs + typedef unsigned short LabelPixelType; + typedef otb::Image<LabelPixelType,Dimension> LabelImageType; + typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8Graph<VertexType> RCC8GraphType; + typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> + RCC8GraphFilterType; + typedef otb::ImageList<LabelImageType> ImageListType; + typedef otb::ImageFileReader<LabelImageType> ReaderType; + typedef otb::RCC8GraphFileWriter<RCC8GraphType> GraphWriterType; + + ImageListType::Pointer inputList = ImageListType::New(); + + // Reading input images + for(int i=3;i<nbImages+2;i++) + { + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFilename(argv[i]); + reader->Update(); + inputList->PushBack(reader->GetOutput()); + } + + // Instanatiation + RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New(); + filter->SetInput(inputList); + + // Writing output graph + GraphWriterType::Pointer writer = GraphWriterType::New(); + writer->SetFilename(outputFilename); + writer->SetInput(filter->GetOutput()); + writer->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/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx new file mode 100644 index 0000000000..215c2bcfd0 --- /dev/null +++ b/Testing/Code/SpatialReasoning/otbImageMultiSegmentationToRCC8GraphFilterNew.cxx @@ -0,0 +1,52 @@ +/*========================================================================= + +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 "otbRCC8Graph.h" +#include "otbImage.h" +#include "otbRCC8VertexBase.h" +#include "otbImageMultiSegmentationToRCC8GraphFilter.h" + +int otbImageMultiSegmentationToRCC8GraphFilterNew(int argc, char* argv[]) +{ +try + { + const unsigned int Dimension = 2; + typedef unsigned short LabelPixelType; + typedef otb::Image<LabelPixelType,Dimension> LabelImageType; + typedef otb::RCC8VertexBase<LabelPixelType> VertexType; + typedef otb::RCC8Graph<VertexType> RCC8GraphType; + typedef otb::ImageMultiSegmentationToRCC8GraphFilter<LabelImageType,RCC8GraphType> + RCC8GraphFilterType; + + // Instanatiation + RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::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/SpatialReasoning/otbSpatialReasoningTests.cxx b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx index 4b950487dd..12975ab849 100644 --- a/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx +++ b/Testing/Code/SpatialReasoning/otbSpatialReasoningTests.cxx @@ -42,5 +42,7 @@ REGISTER_TEST(otbRCC8GraphFileWriter); REGISTER_TEST(otbRCC8GraphFileReaderNew); REGISTER_TEST(otbRCC8GraphFileReader); REGISTER_TEST(otbRCC8GraphIOEndToEnd); -//REGISTER_TEST(otbImageListToRCC8GraphFilterNew); +REGISTER_TEST(otbImageListToRCC8GraphFilterNew); +REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilterNew); +//REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilter); } -- GitLab