diff --git a/Modules/Applications/AppClassification/app/otbClassificationMapRegularization.cxx b/Modules/Applications/AppClassification/app/otbClassificationMapRegularization.cxx index 4652d5556255407d811c591fb0729add8e462b90..e6c026695cbc2456d6367dbec61c7ff72e7352d9 100644 --- a/Modules/Applications/AppClassification/app/otbClassificationMapRegularization.cxx +++ b/Modules/Applications/AppClassification/app/otbClassificationMapRegularization.cxx @@ -99,6 +99,13 @@ private: SetParameterDescription("ip.undecidedlabel", "Label for the Undecided class. By default, 'ip.undecidedlabel = 0'."); SetDefaultParameterInt("ip.undecidedlabel", 0.0); + AddParameter(ParameterType_Empty, "ip.ipobool", "Process isolated pixels only"); + SetParameterDescription("ip.ipobool", "Only pixels whose label is unique in the neighbordhood will be processed. By default, 'ip.ipobool = false'."); + + AddParameter(ParameterType_Int, "ip.ipothres", "Threshold for isolated pixels"); + SetParameterDescription("ip.ipothres", "Maximum number of neighbours with the same label as the center pixel to consider that it is an isolated pixel. By default, 'ip.ipothres = 1'."); + SetDefaultParameterInt("ip.ipothres", 1); + AddRAMParameter(); @@ -107,6 +114,7 @@ private: SetDocExampleParameterValue("io.out", "clLabeledImageQB123_1_CMR_r2_nodl_10_undl_7.tif"); SetDocExampleParameterValue("ip.radius", "2"); SetDocExampleParameterValue("ip.suvbool", "true"); + SetDocExampleParameterValue("ip.ipobool", "true"); SetDocExampleParameterValue("ip.nodatalabel", "10"); SetDocExampleParameterValue("ip.undecidedlabel", "7"); } @@ -149,6 +157,17 @@ private: m_NeighMajVotingFilter->SetKeepOriginalLabelBool(true); } + // Process isolated pixels only + if (IsParameterEnabled("ip.ipobool")) + { + m_NeighMajVotingFilter->SetOnlyIsolatedPixels(true); + m_NeighMajVotingFilter->SetIsolatedThreshold(GetParameterInt("ip.ipothres")); + } + else + { + m_NeighMajVotingFilter->SetOnlyIsolatedPixels(false); + } + /** REGULARIZATION OF CLASSIFICATION */ SetParameterOutputImage<IOLabelImageType>("io.out", m_NeighMajVotingFilter->GetOutput()); diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h index 00e371c3c3ca973e8045bd35efb03ab9fe9f0ac4..2e05ce8bba2fd04f955ad5be896d13f9c00e4c4f 100644 --- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h +++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h @@ -151,6 +151,7 @@ public: //Process only isolated pixels itkSetMacro(OnlyIsolatedPixels, bool); + itkSetMacro(IsolatedThreshold, unsigned int); protected: @@ -195,7 +196,12 @@ private: PixelType m_LabelForNoDataPixels; PixelType m_LabelForUndecidedPixels; bool m_KeepOriginalLabelBool; + + //Choose to filter only isolated pixels bool m_OnlyIsolatedPixels; + //The center pixel is isolated if there are fewer neighbours than + //this threshold with the same label + unsigned int m_IsolatedThreshold; }; // end of class diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx index 75d85125cfde5eb0d182559c8ab91e8cb1b9abef..a9bc792d6f8a931420291f1b3eb713ca10ddd3a6 100644 --- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx +++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx @@ -39,7 +39,8 @@ NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage, TKernel>::Neigh this->SetLabelForUndecidedPixels(itk::NumericTraits<PixelType>::NonpositiveMin()); //m_LabelForUndecidedPixels = 0 this->SetKeepOriginalLabelBool(true); //m_KeepOriginalLabelBool = true this->SetOnlyIsolatedPixels(false); //process all pixels - } + this->SetIsolatedThreshold(1); +} template<class TInputImage, class TOutputImage, class TKernel> @@ -60,9 +61,11 @@ typename NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage, //Get a histogram of label frequencies where the 2 highest are at the beginning and sorted unsigned int freqCenterLabel = this->FillNeighborhoodHistogram(histoNeighVec, nit, kernelBegin, kernelEnd); - if(m_OnlyIsolatedPixels && freqCenterLabel > 1) + if(m_OnlyIsolatedPixels && freqCenterLabel > m_IsolatedThreshold) { - //The center label is not unique in the neighborhood and we only want to filter isolated pixesl + //If we want to filter only isolated pixels, keep the label if + //there are enough pixels with the center label to consider that + //it is not isolated majorityLabel = centerPixel; } else