diff --git a/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.h b/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..38fb59ee57e1d530552589ee35eb2685dd4c6fba --- /dev/null +++ b/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.h @@ -0,0 +1,115 @@ +/*========================================================================= + + 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 __otbMorphologicalProfilesSegmentationFilter_h +#define __otbMorphologicalProfilesSegmentationFilter_h + +#include "otbMorphologicalOpeningProfileFilter.h" +#include "otbMorphologicalClosingProfileFilter.h" +#include "otbProfileToProfileDerivativeFilter.h" +#include "otbProfileDerivativeToMultiScaleCharacteristicsFilter.h" +#include "otbMultiScaleConvexOrConcaveClassificationFilter.h" +#include "otbImage.h" +#include "itkScalarConnectedComponentImageFilter.h" +#include "itkBinaryBallStructuringElement.h" + +namespace otb +{ +/** \class MorphologicalProfilesSegmentationFilter +* +* +*/ + +template <class TInputImage, class TOuputImage, class TInternalPrecision = float, class TStructuringElement = itk::BinaryBallStructuringElement<typename TInputImage::PixelType, TInputImage::ImageDimension> > +class ITK_EXPORT MorphologicalProfilesSegmentationFilter + : public itk::ImageToImageFilter<TInputImage, TOuputImage> +{ +public: +/** Standard Self typedef */ +typedef MorphologicalProfilesSegmentationFilter Self; +typedef itk::ImageToImageFilter<TInputImage, TOuputImage> Superclass; + +typedef itk::SmartPointer<Self> Pointer; +typedef itk::SmartPointer<const Self> ConstPointer; + +/** Some convenient typedefs. */ +typedef TInputImage InputImageType; +typedef typename InputImageType::PixelType InputPixelType; +typedef TOuputImage OutputImageType; +typedef otb::Image<TInternalPrecision> InternalImageType; + +typedef TStructuringElement StructuringElementType; + +typedef otb::MorphologicalOpeningProfileFilter<InputImageType, InternalImageType, StructuringElementType> +OpeningProfileFilterType; +typedef otb::MorphologicalClosingProfileFilter<InputImageType, InternalImageType, StructuringElementType> +ClosingProfileFilterType; +typedef otb::ProfileToProfileDerivativeFilter<InternalImageType, InternalImageType> DerivativeFilterType; +typedef otb::ProfileDerivativeToMultiScaleCharacteristicsFilter<InternalImageType, InternalImageType, OutputImageType> +MultiScaleCharacteristicsFilterType; +typedef otb::MultiScaleConvexOrConcaveClassificationFilter<InternalImageType, + OutputImageType> MultiScaleClassificationFilterType; +typedef itk::ScalarConnectedComponentImageFilter<OutputImageType,OutputImageType> ConnectedComponentsFilterType; + +/** Method for creation through the object factory. */ +itkNewMacro(Self); + +/** Runtime information support. */ +itkTypeMacro(MorphologicalProfilesSegmentationFilter, itk::ImageToImageFilter); + +itkSetMacro(ProfileSize,unsigned int); +itkGetConstReferenceMacro(ProfileSize,unsigned int); +itkSetMacro(ProfileStart,unsigned int); +itkGetConstReferenceMacro(ProfileStart,unsigned int); +itkSetMacro(ProfileStep,unsigned int); +itkGetConstReferenceMacro(ProfileStep,unsigned int); +itkSetMacro(Sigma,double); +itkGetConstReferenceMacro(Sigma,double); + +protected: +MorphologicalProfilesSegmentationFilter(); + +virtual ~MorphologicalProfilesSegmentationFilter(); + +virtual void GenerateData(); + +private: +typename OpeningProfileFilterType::Pointer m_OpeningProfile; +typename ClosingProfileFilterType::Pointer m_ClosingProfile; +typename DerivativeFilterType::Pointer m_OpeningDerivativeProfile; +typename DerivativeFilterType::Pointer m_ClosingDerivativeProfile; +typename MultiScaleCharacteristicsFilterType::Pointer m_OpeningCharacteristicsFilter; +typename MultiScaleCharacteristicsFilterType::Pointer m_ClosingCharacteristicsFilter; +typename MultiScaleClassificationFilterType::Pointer m_ClassificationFilter; +typename ConnectedComponentsFilterType::Pointer m_ConnectedComponentsFilter; + +unsigned int m_ProfileSize; +unsigned int m_ProfileStart; +unsigned int m_ProfileStep; +double m_Sigma; +}; + + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbMorphologicalProfilesSegmentationFilter.txx" +#endif + +#endif + + diff --git a/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.txx b/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..5a0aeb1fc379bf33a4bb2aa28ec7896dbc853496 --- /dev/null +++ b/Code/Segmentation/otbMorphologicalProfilesSegmentationFilter.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 __otbMorphologicalProfilesSegmentationFilter_txx +#define __otbMorphologicalProfilesSegmentationFilter_txx + +#include "otbMorphologicalProfilesSegmentationFilter.h" + +namespace otb +{ + +template <class TInputImage, class TOuputImage, class TInternalPrecision, class TStructuringElement> +MorphologicalProfilesSegmentationFilter<TInputImage,TOuputImage,TInternalPrecision,TStructuringElement> +::MorphologicalProfilesSegmentationFilter() +{ + m_ProfileSize = 5; + m_ProfileStart = 1; + m_ProfileStep = 1; + + m_ClassificationFilter = MultiScaleClassificationFilterType::New(); + m_ConnectedComponentsFilter = ConnectedComponentsFilterType::New(); + m_OpeningProfile = OpeningProfileFilterType::New(); + m_ClosingProfile = ClosingProfileFilterType::New(); + m_OpeningDerivativeProfile = DerivativeFilterType::New(); + m_ClosingDerivativeProfile = DerivativeFilterType::New(); + m_OpeningCharacteristicsFilter = MultiScaleCharacteristicsFilterType::New(); + m_ClosingCharacteristicsFilter = MultiScaleCharacteristicsFilterType::New(); + // Wire pipeline + m_OpeningDerivativeProfile->SetInput(m_OpeningProfile->GetOutput()); + m_ClosingDerivativeProfile->SetInput(m_ClosingProfile->GetOutput()); + m_OpeningCharacteristicsFilter->SetInput(m_OpeningDerivativeProfile->GetOutput()); + m_ClosingCharacteristicsFilter->SetInput(m_ClosingDerivativeProfile->GetOutput()); + + m_ClassificationFilter->SetOpeningProfileDerivativeMaxima(m_OpeningCharacteristicsFilter->GetOutput()); + m_ClassificationFilter->SetOpeningProfileCharacteristics(m_OpeningCharacteristicsFilter->GetOutputCharacteristics()); + m_ClassificationFilter->SetClosingProfileDerivativeMaxima(m_ClosingCharacteristicsFilter->GetOutput()); + m_ClassificationFilter->SetClosingProfileCharacteristics(m_ClosingCharacteristicsFilter->GetOutputCharacteristics()); + + m_ConnectedComponentsFilter->SetInput(m_ClassificationFilter->GetOutput()); + +} + +template <class TInputImage, class TOuputImage, class TInternalPrecision, class TStructuringElement> +MorphologicalProfilesSegmentationFilter<TInputImage,TOuputImage,TInternalPrecision,TStructuringElement> +::~MorphologicalProfilesSegmentationFilter() +{} + +template <class TInputImage, class TOuputImage, class TInternalPrecision, class TStructuringElement> +void +MorphologicalProfilesSegmentationFilter<TInputImage,TOuputImage,TInternalPrecision,TStructuringElement> +::GenerateData() +{ + m_OpeningProfile->SetInput(this->GetInput()); + m_ClosingProfile->SetInput(this->GetInput()); + + m_OpeningProfile->SetProfileSize(m_ProfileSize); + m_OpeningProfile->SetInitialValue(m_ProfileStart); + m_OpeningProfile->SetStep(m_ProfileStep); + + m_ClosingProfile->SetProfileSize(m_ProfileSize); + m_ClosingProfile->SetInitialValue(m_ProfileStart); + m_ClosingProfile->SetStep(m_ProfileStep); + + m_OpeningCharacteristicsFilter->SetInitialValue(m_ProfileStart); + m_OpeningCharacteristicsFilter->SetStep(m_ProfileStep); + + m_ClosingCharacteristicsFilter->SetInitialValue(m_ProfileStart); + m_ClosingCharacteristicsFilter->SetStep(m_ProfileStep); + + m_ClassificationFilter->SetSigma(m_Sigma); + m_ClassificationFilter->SetLabelSeparator(m_ProfileStart + m_ProfileSize * m_ProfileStep); + + m_ConnectedComponentsFilter->GraftOutput(this->GetOutput()); + m_ConnectedComponentsFilter->Update(); + this->GraftOutput(m_ConnectedComponentsFilter->GetOutput()); +} + +} +#endif