From 07b601e919d59f05a7a639e4877f2ebc70ab95cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr>
Date: Mon, 3 Feb 2020 17:26:12 +0100
Subject: [PATCH] ENH: added parameters for maximum error and maximum kernel
 width in Smoothing

---
 .../AppFiltering/app/otbSmoothing.cxx             | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Modules/Applications/AppFiltering/app/otbSmoothing.cxx b/Modules/Applications/AppFiltering/app/otbSmoothing.cxx
index dad4b5039f..c221db68f2 100644
--- a/Modules/Applications/AppFiltering/app/otbSmoothing.cxx
+++ b/Modules/Applications/AppFiltering/app/otbSmoothing.cxx
@@ -90,8 +90,17 @@ private:
     SetParameterDescription("type.gaussian.stdev", "Standard deviation of the gaussian kernel used to filter the image");
     SetDefaultParameterFloat("type.gaussian.stdev", 2.0);
 
-    AddChoice("type.anidif", "Anisotropic Diffusion");
+    AddParameter(ParameterType_Float, "type.gaussian.maxerror", "Maximum error");
+    SetParameterDescription("type.gaussian.stdev", "The algorithm will size the discrete kernel so that the error "
+                            "resulting from truncation of the kernel is no greater than maxerror.");
+    SetDefaultParameterFloat("type.gaussian.maxerror", 0.01);
+
+    AddParameter(ParameterType_Int, "type.gaussian.maxwidth", "Maximum kernel width");
+    SetParameterDescription("type.gaussian.maxwidth", "Set the kernel to be no wider than maxwidth pixels, "
+                             "even if type.gaussian.maxerror demands it.");
+    SetDefaultParameterInt("type.gaussian.maxwidth", 32);
 
+    AddChoice("type.anidif", "Anisotropic Diffusion");
 
     AddParameter(ParameterType_Float, "type.anidif.timestep", "Time Step");
     SetParameterDescription("type.anidif.timestep", "Time step that will be used to discretize the diffusion equation");
@@ -175,8 +184,12 @@ private:
 
       const double stdev = GetParameterFloat("type.gaussian.stdev");
       double variance = stdev * stdev;
+      
       perBand->GetFilter()->SetVariance(variance);
       perBand->GetFilter()->SetUseImageSpacing(false);
+      perBand->GetFilter()->SetMaximumError(GetParameterFloat("type.gaussian.maxerror"));
+      perBand->GetFilter()->SetMaximumKernelWidth(GetParameterInt("type.gaussian.maxwidth"));
+      
       perBand->UpdateOutputInformation();
       m_FilterRef = perBand;
       SetParameterOutputImage("out", perBand->GetOutput());
-- 
GitLab