diff --git a/Code/OBIA/otbMeanShiftSegmentationFilter.h b/Code/OBIA/otbMeanShiftSegmentationFilter.h index c8c80524dd5f41b02362c1299fa0768efec338e6..760017e0de133039c54f2586bb1f4786d46b02b8 100644 --- a/Code/OBIA/otbMeanShiftSegmentationFilter.h +++ b/Code/OBIA/otbMeanShiftSegmentationFilter.h @@ -78,6 +78,32 @@ public: itkSetObjectMacro(RegionMergingFilter, RegionMergingFilterType); itkGetObjectMacro(RegionMergingFilter, RegionMergingFilterType); + /** Sets the spatial bandwidth (or radius in the case of a uniform kernel) + * of the neighborhood for each pixel + */ + virtual void SetSpatialBandwidth(const RealType _arg) + { + this->m_MeanShiftFilter->SetSpatialBandwidth(_arg); + } + virtual RealType GetSpatialBandwidth () + { + return this->m_MeanShiftFilter->GetSpatialBandwidth(); + } + + + /** Sets the spectral bandwidth (or radius for a uniform kernel) for pixels + * to be included in the same mode + */ + virtual void SetRangeBandwidth(const RealType _arg) + { + this->m_MeanShiftFilter->SetRangeBandwidth(_arg); + } + virtual RealType GetRangeBandwidth () + { + return this->m_MeanShiftFilter->GetRangeBandwidth(); + } + + /** Returns the const image of region labels */ const OutputLabelImageType * GetLabelOutput() const; /** Returns the image of region labels */ @@ -94,7 +120,7 @@ protected: void GenerateInputRequestedRegion(); - virtual void GenerateOutputInformation(void); +// virtual void GenerateOutputInformation(void); virtual void GenerateData(); diff --git a/Code/OBIA/otbMeanShiftSegmentationFilter.txx b/Code/OBIA/otbMeanShiftSegmentationFilter.txx index 21d059dd09b73250195361ac5a3aae9944d97195..a03e1b0ba23a52aaaa61e92ff78b5286569bdc70 100644 --- a/Code/OBIA/otbMeanShiftSegmentationFilter.txx +++ b/Code/OBIA/otbMeanShiftSegmentationFilter.txx @@ -30,6 +30,7 @@ MeanShiftSegmentationFilter<TInputImage, TOutputLabelImage, TOutputClusteredImag m_RegionMergingFilter = RegionMergingFilterType::New(); this->SetNumberOfOutputs(2); + this->SetNthOutput(0, m_RegionMergingFilter->GetLabelOutput()); this->SetNthOutput(1, m_RegionMergingFilter->GetClusteredOutput()); } @@ -81,21 +82,21 @@ MeanShiftSegmentationFilter<TInputImage, TOutputLabelImage, TOutputClusteredImag return static_cast<OutputClusteredImageType *>(this->m_RegionMergingFilter->GetClusteredOutput()); } -template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel> -void -MeanShiftSegmentationFilter<TInputImage, TOutputLabelImage, TOutputClusteredImage, TKernel> -::GenerateOutputInformation() -{ - Superclass::GenerateOutputInformation(); +// template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel> +// void +// MeanShiftSegmentationFilter<TInputImage, TOutputLabelImage, TOutputClusteredImage, TKernel> +// ::GenerateOutputInformation() +// { +// Superclass::GenerateOutputInformation(); - unsigned int numberOfComponentsPerPixel = this->GetInputSpectralImage()->GetNumberOfComponentsPerPixel(); +// unsigned int numberOfComponentsPerPixel = this->GetInput()->GetNumberOfComponentsPerPixel(); - if(this->GetClusteredOutput()) - { - this->GetClusteredOutput()->SetNumberOfComponentsPerPixel(numberOfComponentsPerPixel); - } +// if(this->GetClusteredOutput()) +// { +// this->GetClusteredOutput()->SetNumberOfComponentsPerPixel(numberOfComponentsPerPixel); +// } -} +// } template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel> @@ -105,9 +106,11 @@ MeanShiftSegmentationFilter<TInputImage, TOutputLabelImage, TOutputClusteredImag { this->m_MeanShiftFilter->SetInput(this->GetInput()); + this->m_MeanShiftFilter->Update(); - this->m_RegionMergingFilter->SetInputLabelImage(this->m_RegionMergingFilter->GetLabelOutput()); - this->m_RegionMergingFilter->SetInputSpectralImage(this->m_RegionMergingFilter->GetRangeOutput()); + this->m_RegionMergingFilter->SetInputLabelImage(this->m_MeanShiftFilter->GetLabelOutput()); + this->m_RegionMergingFilter->SetInputSpectralImage(this->m_MeanShiftFilter->GetRangeOutput()); + this->m_RegionMergingFilter->SetRangeBandwidth(this->GetRangeBandwidth()); this->m_RegionMergingFilter->Update();