diff --git a/Code/MultiScale/otbImageToProfileFilter.h b/Code/MultiScale/otbImageToProfileFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..220d21458341015e7bc94072c7af546a3ef58eb6 --- /dev/null +++ b/Code/MultiScale/otbImageToProfileFilter.h @@ -0,0 +1,123 @@ +/*========================================================================= + +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 _otbImageToProfileFilter_h +#define _otbImageToProfileFilter_h + +#include "otbImageToImageListFilter.h" + +namespace otb +{ +/** \class ImageToProfileFilter + * \brief Base class to produce a profile of the response of a given filter for a range of parameter. + * + * Let \f$f\$ denote an image, and \f$\phi_{N}\f$ an image operator with the parameter \f$N\f$. + * A profile \f$\Pi_{\phi}(f)\f$ of \f$f\f$ by \f$\phi\f$ is defined as follows: + * \f[ + * \Pi_{\phi}(f)= \{\phi_{n}(f), n \in \{n_{1},\ldots,n_{N}\} \} + * \f] + * + * with \f$\{n_{1},\ldots,n_{N}\}\f$ beeing a range of parameter. This class is a base class templated + * by the type of the filter \f$\pĥi\f$. The SetProfileParameter() is a virtual method meant to be + * rewritten so that the filter can be correctly set up in sub-classes. + * + * \sa MorphologicalOpeningProfileFilter + * \sa MorhologicalClosingProfileFilter + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter = unsigned int> +class ITK_EXPORT ImageToProfileFilter + : public ImageToImageListFilter<TInputImage,TOutputImage> +{ + public: + /** Standard typedefs */ + typedef ImageToProfileFilter Self; + typedef ImageToImageListFilter<TInputImage,TOutputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(ImageToProfileFilter, ImageToImageListFilter); + + /** Template parameters typedefs */ + typedef TInputImage InputImageType; + typedef TOutputImage OutputImageType; + typedef TParameter ParameterType; + typedef TFilter FilterType; + typedef typename FilterType::Pointer FilterPointerType; + typedef typename Superclass::OutputImageListType OutputImageListType; + typedef typename Superclass::OutputImageListPointerType OutputImageListPointerType; + typedef typename Superclass::InputImagePointer InputImagePointerType; + + /** Get/Set the initial value */ + itkSetMacro(InitialValue,ParameterType); + itkGetMacro(InitialValue,ParameterType); + /** Get/Set the profile size */ + itkSetMacro(ProfileSize,unsigned int); + itkGetMacro(ProfileSize,unsigned int); + /** Get/Set the profile step */ + itkSetMacro(Step,ParameterType); + itkGetMacro(Step,ParameterType); + /** Get/Set the output index */ + itkSetMacro(OutputIndex,unsigned int); + itkGetMacro(OutputIndex,unsigned int); + +protected: + /** + * Set the profile parameter + * \param param The parameter to set + */ + virtual void SetProfileParameter(ParameterType param){}; + /** Get the pointer to the filter */ + itkGetObjectMacro(Filter,FilterType); + /** GenerateData method */ + virtual void GenerateData(void); + /** GenerateOutputInformation method */ + virtual void GenerateOutputInformation(void); + /** Generate input requested region */ + virtual void GenerateInputRequestedRegion(void); + /** Constructor */ + ImageToProfileFilter(); + /** Destructor */ + virtual ~ImageToProfileFilter() {}; + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageToProfileFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + /** The filter used to compute the profile */ + FilterPointerType m_Filter; + /** The profile parameters */ + unsigned int m_ProfileSize; + /** Initial value */ + ParameterType m_InitialValue; + /** Step */ + ParameterType m_Step; + /** The index of the output of the filter used for the profile */ + unsigned int m_OutputIndex; + +}; +}// End namespace otb +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageToProfileFilter.txx" +#endif + +#endif diff --git a/Code/MultiScale/otbImageToProfileFilter.txx b/Code/MultiScale/otbImageToProfileFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..7e08adcc6c71eeeb5b6a60746f06f529e33b3494 --- /dev/null +++ b/Code/MultiScale/otbImageToProfileFilter.txx @@ -0,0 +1,141 @@ +/*========================================================================= + +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 _otbImageToProfileFilter_txx +#define _otbImageToProfileFilter_txx + +#include "otbImageToProfileFilter.h" + +namespace otb +{ +/** + * Constructor + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter> +ImageToProfileFilter<TInputImage,TOutputImage,TFilter,TParameter> +::ImageToProfileFilter() +{ + m_InitialValue = 0; + m_Step = 1; + m_ProfileSize = 10; + m_OutputIndex = 0; + m_Filter= FilterType::New(); +} +/** + * GenerateOutputInformation method + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter> +void +ImageToProfileFilter<TInputImage,TOutputImage,TFilter,TParameter> +::GenerateOutputInformation(void) +{ + // Retrieving input/output pointers + InputImagePointerType inputPtr = this->GetInput(); + OutputImageListPointerType outputPtr = this->GetOutput(); + if(outputPtr) + { + if(outputPtr->Size()!=m_ProfileSize) + { + // in this case, clear the list + outputPtr->Clear(); + for(unsigned int i = 0;i<m_ProfileSize;++i) + { + //Create the output image + outputPtr->PushBack(OutputImageType::New()); + } + } + // For each output image + typename OutputImageListType::Iterator outputListIt = outputPtr->Begin(); + m_Filter->SetInput(inputPtr); + m_Filter->UpdateOutputInformation(); + while(outputListIt!=outputPtr->End()) + { + //Set the image information + outputListIt.Get()->CopyInformation(m_Filter->GetOutput(m_OutputIndex)); + outputListIt.Get()->SetLargestPossibleRegion(m_Filter->GetOutput(m_OutputIndex)->GetLargestPossibleRegion()); + ++outputListIt; + } + } +} +/** + * Generate input requested region + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter> +void +ImageToProfileFilter<TInputImage,TOutputImage,TFilter,TParameter> +::GenerateInputRequestedRegion(void) +{ + // Retrieving input/output pointers + InputImagePointerType inputPtr = this->GetInput(); + OutputImageListPointerType outputPtr = this->GetOutput(); + + // For each output image + typename OutputImageListType::Iterator outputListIt = outputPtr->Begin(); + + m_Filter->SetInput(inputPtr); + + // Use the filter to generate input requested region + while(outputListIt!=outputPtr->End()) + { + m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion()); + m_Filter->PropagateRequestedRegion(outputListIt.Get()); + ++outputListIt; + } +} +/** + * GenerateData method + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter> +void +ImageToProfileFilter<TInputImage,TOutputImage,TFilter,TParameter> +::GenerateData(void) +{ + // Retrieving input/output pointers + InputImagePointerType inputPtr = this->GetInput(); + OutputImageListPointerType outputPtr = this->GetOutput(); + m_Filter->SetInput(inputPtr); + + for(unsigned int i = 0;i<m_ProfileSize;++i) + { + ParameterType profileParameter = m_InitialValue + static_cast<ParameterType>(i)*m_Step; + this->SetProfileParameter(profileParameter); + m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputPtr->GetNthElement(i)->GetRequestedRegion()); + m_Filter->Update(); + outputPtr->SetNthElement(i,static_cast<OutputImageType *>(m_Filter->GetOutput(m_OutputIndex))); + outputPtr->GetNthElement(i)->DisconnectPipeline(); + } +} + +/** + * PrintSelf Method + */ +template <class TInputImage, class TOutputImage, class TFilter, class TParameter> +void +ImageToProfileFilter<TInputImage,TOutputImage,TFilter,TParameter> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os<<indent<<"Filter: " <<m_Filter->GetNameOfClass() <<std::endl; + os<<indent<<"OutputIndex: " <<m_OutputIndex <<std::endl; + os<<indent<<"ProfileSize: " <<m_ProfileSize <<std::endl; + os<<indent<<"InitialValue: "<<m_InitialValue <<std::endl; + os<<indent<<"Step: " <<m_Step <<std::endl; + + +} +} // End namespace otb +#endif diff --git a/Code/MultiScale/otbMorphologicalClosingProfileFilter.h b/Code/MultiScale/otbMorphologicalClosingProfileFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..c81c76854e0569ed56d950e494bc94cac38652ca --- /dev/null +++ b/Code/MultiScale/otbMorphologicalClosingProfileFilter.h @@ -0,0 +1,96 @@ +/*========================================================================= + +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 _otbMorphologicalClosingProfileFilter_h +#define _otbMorphologicalClosingProfileFilter_h + +#include "otbImageToProfileFilter.h" +#include "itkClosingByReconstructionImageFilter.h" + +namespace otb +{ +/** \class MorphologicalClosingProfileFilter + * \brief This filter compute the morphological closing profile. + * + * This algorithm is based on the following publication: + * \par + * Martino Pesaresi and Jon Alti Benediktsson, Member, IEEE: + * A new approach for the morphological segmentation of high resolution + * satellite imagery. IEEE Transactions on geoscience and remote sensing, vol. 39, + * NO. 2, February 2001, p. 309-320. + * \par + * + * The opening profile is a set of images beeing the result of a geodesic morphological + * closing by reconstruction with an increasing range of structuring element sizes. + * + * For more informations on profiles please refer to the documentation of the otb::ImageToProfileFilter + * class. + * + * \sa ImageToProfileFilter + * \sa itk::ClosingByReconstructionImageFilter + */ +template <class TInputImage,class TOutputImage, class TStructuringElement> +class ITK_EXPORT MorphologicalClosingProfileFilter + : public ImageToProfileFilter<TInputImage,TOutputImage, + itk::ClosingByReconstructionImageFilter + <TInputImage, TOutputImage, TStructuringElement>, + unsigned int> +{ + public: + /** Standard typedefs */ + typedef MorphologicalClosingProfileFilter Self; + typedef ImageToProfileFilter<TInputImage,TOutputImage, + itk::ClosingByReconstructionImageFilter + <TInputImage, TOutputImage, TStructuringElement>, + unsigned int> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(MorphologicalClosingProfileFilter,ImageToProfileFilter); + + typedef TStructuringElement StructuringElementType; + typedef typename Superclass::ParameterType ParameterType; + +protected: + /** Set the profile parameter */ + virtual void SetProfileParameter(ParameterType param) + { + StructuringElementType se; + se.SetRadius(param); + se.CreateStructuringElement(); + this->GetFilter()->SetKernel(se); + }; + /** Constructor */ + MorphologicalClosingProfileFilter(){}; + /** Destructor */ + virtual ~MorphologicalClosingProfileFilter(){}; + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + }; + +private: + MorphologicalClosingProfileFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; +}// End namespace otb +#endif diff --git a/Code/MultiScale/otbMorphologicalOpeningProfileFilter.h b/Code/MultiScale/otbMorphologicalOpeningProfileFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..58cce264fbca0d757d001934883133ef14037610 --- /dev/null +++ b/Code/MultiScale/otbMorphologicalOpeningProfileFilter.h @@ -0,0 +1,96 @@ +/*========================================================================= + +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 _otbMorphologicalOpeningProfileFilter_h +#define _otbMorphologicalOpeningProfileFilter_h + +#include "otbImageToProfileFilter.h" +#include "itkOpeningByReconstructionImageFilter.h" + +namespace otb +{ +/** \class MorphologicalOpeningProfileFilter + * \brief This filter compute the morphological opening profile. + * + * This algorithm is based on the following publication: + * \par + * Martino Pesaresi and Jon Alti Benediktsson, Member, IEEE: + * A new approach for the morphological segmentation of high resolution + * satellite imagery. IEEE Transactions on geoscience and remote sensing, vol. 39, + * NO. 2, February 2001, p. 309-320. + * \par + * + * The opening profile is a set of images beeing the result of a geodesic morphological + * opening by reconstruction with an increasing range of structuring element sizes. + * + * For more informations on profiles please refer to the documentation of the otb::ImageToProfileFilter + * class. + * + * \sa ImageToProfileFilter + * \sa itk::OpeningByReconstructionImageFilter + */ +template <class TInputImage,class TOutputImage, class TStructuringElement> +class ITK_EXPORT MorphologicalOpeningProfileFilter + : public ImageToProfileFilter<TInputImage,TOutputImage, + itk::OpeningByReconstructionImageFilter + <TInputImage, TOutputImage, TStructuringElement>, + unsigned int> +{ + public: + /** Standard typedefs */ + typedef MorphologicalOpeningProfileFilter Self; + typedef ImageToProfileFilter<TInputImage,TOutputImage, + itk::OpeningByReconstructionImageFilter + <TInputImage, TOutputImage, TStructuringElement>, + unsigned int> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(MorphologicalOpeningProfileFilter,ImageToProfileFilter); + + typedef TStructuringElement StructuringElementType; + typedef typename Superclass::ParameterType ParameterType; + +protected: + /** Set the profile parameter */ + virtual void SetProfileParameter(ParameterType param) + { + StructuringElementType se; + se.SetRadius(param); + se.CreateStructuringElement(); + this->GetFilter()->SetKernel(se); + }; + /** Constructor */ + MorphologicalOpeningProfileFilter(){}; + /** Destructor */ + virtual ~MorphologicalOpeningProfileFilter(){}; + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + }; + +private: + MorphologicalOpeningProfileFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; +}// End namespace otb +#endif diff --git a/Testing/Code/MultiScale/CMakeLists.txt b/Testing/Code/MultiScale/CMakeLists.txt index b9aa6a7299bde3edd073c38abe27842715fcf952..8dba9d0aa54a4a4c6bfffad8d3c32fa5057debde 100644 --- a/Testing/Code/MultiScale/CMakeLists.txt +++ b/Testing/Code/MultiScale/CMakeLists.txt @@ -215,6 +215,54 @@ ADD_TEST(msTvConvexOrConcaveClassificationFilter ${MULTISCALE_TESTS2} 0.5 ) +# ------- otb::MorphologicalOpeningProfileFilter ---------- + +ADD_TEST(msTuMorphologicalOpeningProfileFilterNew ${MULTISCALE_TESTS2} + otbMorphologicalOpeningProfileFilterNew) + +ADD_TEST(msTvMorphologicalOpeningProfileFilter ${MULTISCALE_TESTS2} + --compare-n-images ${TOL} 4 + ${BASELINE}/msMorphologicalOpeningProfileFilterOutput1.tif + ${TEMP}/msMorphologicalOpeningProfileFilterOutput1.tif + ${BASELINE}/msMorphologicalOpeningProfileFilterOutput2.tif + ${TEMP}/msMorphologicalOpeningProfileFilterOutput2.tif + ${BASELINE}/msMorphologicalOpeningProfileFilterOutput3.tif + ${TEMP}/msMorphologicalOpeningProfileFilterOutput3.tif + ${BASELINE}/msMorphologicalOpeningProfileFilterOutput4.tif + ${TEMP}/msMorphologicalOpeningProfileFilterOutput4.tif + otbMorphologicalOpeningProfileFilter + ${INPUTDATA}/ROI_IKO_PAN_LesHalles.tif + ${TEMP}/msMorphologicalOpeningProfileFilterOutput + tif + 4 + 1 + 1 +) + +# ------- otb::MorphologicalClosingProfileFilter ---------- + +ADD_TEST(msTuMorphologicalClosingProfileFilterNew ${MULTISCALE_TESTS2} + otbMorphologicalClosingProfileFilterNew) + +ADD_TEST(msTvMorphologicalClosingProfileFilter ${MULTISCALE_TESTS2} + --compare-n-images ${TOL} 4 + ${BASELINE}/msMorphologicalClosingProfileFilterOutput1.tif + ${TEMP}/msMorphologicalClosingProfileFilterOutput1.tif + ${BASELINE}/msMorphologicalClosingProfileFilterOutput2.tif + ${TEMP}/msMorphologicalClosingProfileFilterOutput2.tif + ${BASELINE}/msMorphologicalClosingProfileFilterOutput3.tif + ${TEMP}/msMorphologicalClosingProfileFilterOutput3.tif + ${BASELINE}/msMorphologicalClosingProfileFilterOutput4.tif + ${TEMP}/msMorphologicalClosingProfileFilterOutput4.tif + otbMorphologicalClosingProfileFilter + ${INPUTDATA}/ROI_IKO_PAN_LesHalles.tif + ${TEMP}/msMorphologicalClosingProfileFilterOutput + tif + 4 + 1 + 1 +) + # ------- Fichiers sources CXX ----------------------------------- SET(BasicMultiScale_SRCS1 otbMorphologicalPyramidResamplerNew.cxx @@ -237,6 +285,10 @@ otbGeodesicMorphologyLevelingFilterNew.cxx otbGeodesicMorphologyLevelingFilter.cxx otbConvexOrConcaveClassificationFilterNew.cxx otbConvexOrConcaveClassificationFilter.cxx +otbMorphologicalOpeningProfileFilterNew.cxx +otbMorphologicalOpeningProfileFilter.cxx +otbMorphologicalClosingProfileFilterNew.cxx +otbMorphologicalClosingProfileFilter.cxx ) diff --git a/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilter.cxx b/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a33f844c9180c6fa60de8d6efd2298b7beb44efd --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilter.cxx @@ -0,0 +1,78 @@ +/*========================================================================= + +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 "otbMorphologicalClosingProfileFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbImage.h" + +#include "itkMacro.h" + +int otbMorphologicalClosingProfileFilter(int argc, char * argv[]) +{ + const char * inputFilename = argv[1]; + const char * outputFilenamePrefix = argv[2]; + const char * outputFilenameSuffix = argv[3]; + const unsigned int profileSize = atoi(argv[4]); + const unsigned int initialValue = atoi(argv[5]); + const unsigned int step = atoi(argv[5]); + + + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef double OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::StreamingImageFileWriter<OutputImageType> WriterType; + + typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType; + typedef otb::MorphologicalClosingProfileFilter<InputImageType,InputImageType,StructuringElementType> + ClosingProfileFilterType; + + // Reading input image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(inputFilename); + + // Instantiation + ClosingProfileFilterType::Pointer profileFilter = ClosingProfileFilterType::New(); + profileFilter->SetInput(reader->GetOutput()); + profileFilter->SetProfileSize(profileSize); + profileFilter->SetInitialValue(initialValue); + profileFilter->SetStep(step); + profileFilter->Update(); + + WriterType::Pointer writer; + + // std::stringstream oss; + itk::OStringStream oss; + // Writing the results images + for(unsigned int i = 1;i<=profileSize;++i) + { + writer = WriterType::New(); + oss<<outputFilenamePrefix<<i<<"."<<outputFilenameSuffix; + writer->SetInput(profileFilter->GetOutput()->GetNthElement(i-1)); + writer->SetFileName(oss.str().c_str()); + writer->Update(); + oss.str(""); + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilterNew.cxx b/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..318daa86d425277f6f0778f8e04dfee990ce6276 --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalClosingProfileFilterNew.cxx @@ -0,0 +1,41 @@ +/*========================================================================= + +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 "otbMorphologicalClosingProfileFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "otbImage.h" + +#include "itkMacro.h" + +int otbMorphologicalClosingProfileFilterNew(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef double OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType; + typedef otb::MorphologicalClosingProfileFilter<InputImageType,InputImageType,StructuringElementType> + ClosingProfileFilterType; + + // Instantiation + ClosingProfileFilterType::Pointer profileFilter = ClosingProfileFilterType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilter.cxx b/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..02f32bf0f4e72ad3ef033f8989db05ba56aa3de5 --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilter.cxx @@ -0,0 +1,78 @@ +/*========================================================================= + +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 "otbMorphologicalOpeningProfileFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" +#include "otbImage.h" + +#include "itkMacro.h" + +int otbMorphologicalOpeningProfileFilter(int argc, char * argv[]) +{ + const char * inputFilename = argv[1]; + const char * outputFilenamePrefix = argv[2]; + const char * outputFilenameSuffix = argv[3]; + const unsigned int profileSize = atoi(argv[4]); + const unsigned int initialValue = atoi(argv[5]); + const unsigned int step = atoi(argv[5]); + + + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef double OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::StreamingImageFileWriter<OutputImageType> WriterType; + + typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType; + typedef otb::MorphologicalOpeningProfileFilter<InputImageType,InputImageType,StructuringElementType> + OpeningProfileFilterType; + + // Reading input image + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(inputFilename); + + // Instantiation + OpeningProfileFilterType::Pointer profileFilter = OpeningProfileFilterType::New(); + profileFilter->SetInput(reader->GetOutput()); + profileFilter->SetProfileSize(profileSize); + profileFilter->SetInitialValue(initialValue); + profileFilter->SetStep(step); + profileFilter->Update(); + + WriterType::Pointer writer; + + // std::stringstream oss; + itk::OStringStream oss; + // Writing the results images + for(unsigned int i = 1;i<=profileSize;++i) + { + writer = WriterType::New(); + oss<<outputFilenamePrefix<<i<<"."<<outputFilenameSuffix; + writer->SetInput(profileFilter->GetOutput()->GetNthElement(i-1)); + writer->SetFileName(oss.str().c_str()); + writer->Update(); + oss.str(""); + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilterNew.cxx b/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f62dcc8c9872ee7c2e93797c5778d717c36bc54c --- /dev/null +++ b/Testing/Code/MultiScale/otbMorphologicalOpeningProfileFilterNew.cxx @@ -0,0 +1,41 @@ +/*========================================================================= + +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 "otbMorphologicalOpeningProfileFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "otbImage.h" + +#include "itkMacro.h" + +int otbMorphologicalOpeningProfileFilterNew(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef double OutputPixelType; + + typedef otb::Image<InputPixelType,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType; + typedef otb::MorphologicalOpeningProfileFilter<InputImageType,InputImageType,StructuringElementType> + OpeningProfileFilterType; + + // Instantiation + OpeningProfileFilterType::Pointer profileFilter = OpeningProfileFilterType::New(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/MultiScale/otbMultiScaleTests2.cxx b/Testing/Code/MultiScale/otbMultiScaleTests2.cxx index 8fc7064c2dc7a92fcdf7634dc90f35b08807da12..af049b7a147021cec717ba47b6bb9d6797510b60 100644 --- a/Testing/Code/MultiScale/otbMultiScaleTests2.cxx +++ b/Testing/Code/MultiScale/otbMultiScaleTests2.cxx @@ -34,4 +34,8 @@ REGISTER_TEST(otbGeodesicMorphologyLevelingFilterNew); REGISTER_TEST(otbGeodesicMorphologyLevelingFilter); REGISTER_TEST(otbConvexOrConcaveClassificationFilterNew); REGISTER_TEST(otbConvexOrConcaveClassificationFilter); +REGISTER_TEST(otbMorphologicalOpeningProfileFilterNew); +REGISTER_TEST(otbMorphologicalOpeningProfileFilter); +REGISTER_TEST(otbMorphologicalClosingProfileFilterNew); +REGISTER_TEST(otbMorphologicalClosingProfileFilter); }