From 6e0113995188fb6d1289c285c97d0ac750e23bff Mon Sep 17 00:00:00 2001
From: Guillaume Borrut <guillaume.borrut@c-s.fr>
Date: Thu, 29 Jan 2009 18:35:51 +0100
Subject: [PATCH] ENH: Turning CloudDetection into CloudEstimator

---
 .../otbCloudDetectionFilter.h                 |  33 ++---
 .../otbCloudDetectionFilter.txx               |  61 +++++++--
 .../otbCloudDetectionFunctor.h                | 125 ++++++++++++++++++
 .../otbCloudEstimatorFilter.h                 |  87 ++++++++++++
 .../otbCloudEstimatorFilter.txx               | 111 ++++++++++++++++
 .../otbCloudEstimatorFunctor.h                | 125 ++++++++++++++++++
 Testing/Code/FeatureExtraction/CMakeLists.txt |  47 +++++--
 .../otbCloudEstimatorDefaultFilter.cxx        |  71 ++++++++++
 .../otbCloudEstimatorFilter.cxx               |  73 ++++++++++
 .../otbCloudEstimatorFilterNew.cxx            |  36 +++++
 .../otbFeatureExtractionTests11.cxx           |   7 +-
 11 files changed, 730 insertions(+), 46 deletions(-)
 create mode 100644 Code/FeatureExtraction/otbCloudDetectionFunctor.h
 create mode 100644 Code/FeatureExtraction/otbCloudEstimatorFilter.h
 create mode 100644 Code/FeatureExtraction/otbCloudEstimatorFilter.txx
 create mode 100644 Code/FeatureExtraction/otbCloudEstimatorFunctor.h
 create mode 100644 Testing/Code/FeatureExtraction/otbCloudEstimatorDefaultFilter.cxx
 create mode 100644 Testing/Code/FeatureExtraction/otbCloudEstimatorFilter.cxx
 create mode 100644 Testing/Code/FeatureExtraction/otbCloudEstimatorFilterNew.cxx

diff --git a/Code/FeatureExtraction/otbCloudDetectionFilter.h b/Code/FeatureExtraction/otbCloudDetectionFilter.h
index d8ed658abe..7d7427c794 100644
--- a/Code/FeatureExtraction/otbCloudDetectionFilter.h
+++ b/Code/FeatureExtraction/otbCloudDetectionFilter.h
@@ -28,17 +28,15 @@ namespace otb
  * \brief Apply a threshold.
  * \brief Apply a color reversal.
  */
-template <class TInputImage, class TOutputImage>
-class ITK_EXPORT CloudDetectionFilter :  public itk::UnaryFunctorImageFilter< TInputImage, TOutputImage,                                       /* TFunction =*/ Functor::SpectralAngleFunctor< ITK_TYPENAME TInputImage::PixelType, 
-                                                    ITK_TYPENAME TOutputImage::PixelType> >
+template <class TInputImage, class TOutputImage, class TFunction = Functor::SpectralAngleFunctor< 
+                                          ITK_TYPENAME TInputImage::PixelType, ITK_TYPENAME TOutputImage::PixelType> >
+class ITK_EXPORT CloudDetectionFilter : public itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, TFunction >
 {
 public:
   /** Standard class typedefs. */
   typedef CloudDetectionFilter                           Self;
-  typedef typename itk::UnaryFunctorImageFilter < TInputImage,
-                                                  TOutputImage,
-                                                    Functor::SpectralAngleFunctor < typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass;
-
+  typedef typename itk::UnaryFunctorImageFilter < TInputImage, TOutputImage, TFunction > 
+                                                        Superclass;
   typedef itk::SmartPointer<Self>                       Pointer;
   typedef itk::SmartPointer<const Self>                 ConstPointer;
 
@@ -57,18 +55,12 @@ public:
   typedef typename OutputImageType::RegionType    OutputImageRegionType;
   typedef typename OutputImageType::PixelType     OutputPixelType;
 
- 
-  itkSetMacro(Variance, double);
-  itkGetMacro(Variance, double);
-  itkSetMacro(Threshold, double);
-  itkGetMacro(Threshold, double);
+  /** Getters/Setters */
+  void SetReferencePixel( InputPixelType ref );
+  InputPixelType GetReferencePixel();
+  void SetVariance( double var );
+  double GetVariance();
 
-  void SetReferencePixel( InputPixelType ref ){ this->GetFunctor().SetReferencePixel( ref ); };
-  InputPixelType GetReferencePixel(){ return this->GetFunctor().GetReferencePixel(); };
-  
-/*  void SetVariance(double var){ this->GetFunctor().SetVariance( var ); };
-  double GetVariance(){ return this->GetFunctor().GetVariance();
-*/
 
 protected:
   CloudDetectionFilter();
@@ -83,11 +75,6 @@ private:
   CloudDetectionFilter(const Self&); //purposely not implemented
   void operator=(const Self&); //purposely not implemented
 
-  /** Gaussian parameter */
-  double m_Variance;
-
-  /** Threshold for the binary image */
-  double m_Threshold;
 
 };
 
diff --git a/Code/FeatureExtraction/otbCloudDetectionFilter.txx b/Code/FeatureExtraction/otbCloudDetectionFilter.txx
index e984d526dd..08f0a5d66b 100644
--- a/Code/FeatureExtraction/otbCloudDetectionFilter.txx
+++ b/Code/FeatureExtraction/otbCloudDetectionFilter.txx
@@ -27,37 +27,31 @@ namespace otb
 /**
  * Constructor
  */
-template <class TInputImage,class TOutputImage>
-CloudDetectionFilter<TInputImage,TOutputImage>
+template <class TInputImage, class TOutputImage, class TFunction>
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
 ::CloudDetectionFilter()
 {
-
-  this->SetThreshold(1000);
-  this->SetVariance(1);
-
 }
 
 /**
  * Printself
  */
-template <class TInputImage,class TOutputImage>
+template <class TInputImage, class TOutputImage, class TFunction>
 void
-CloudDetectionFilter<TInputImage,TOutputImage>
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
 ::PrintSelf(std::ostream& os, itk::Indent indent) const
 {
 
   this->Superclass::PrintSelf(os,indent);
-  os << indent << "Variance  : " << m_Variance  <<std::endl;
-  os << indent << "Threshold : " << m_Threshold <<std::endl;
 
 }
 
 /**
  * BeforeThreadedGenerateData
  */
-template <class TInputImage,class TOutputImage >
+template <class TInputImage, class TOutputImage, class TFunction>
 void
-CloudDetectionFilter<TInputImage,TOutputImage>
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
 ::BeforeThreadedGenerateData()
 {
 
@@ -71,6 +65,49 @@ CloudDetectionFilter<TInputImage,TOutputImage>
 
 }
 
+/**
+ * SetVariance
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
+::SetVariance(double var)
+{
+  this->GetFunctor().SetVariance( var );
+}
+
+/**
+ * GetVariance
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+double
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
+::GetVariance()
+{
+  return this->GetFunctor().GetVariance();
+}
+
+/**
+ * SetReferencePixel
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
+::SetReferencePixel(InputPixelType ref)
+{
+  this->GetFunctor().SetReferencePixel( ref );
+}
+
+/**
+ * GetReferencePixel
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+typename CloudDetectionFilter<TInputImage,TOutputImage,TFunction>::InputPixelType
+CloudDetectionFilter<TInputImage,TOutputImage,TFunction>
+::GetReferencePixel()
+{
+  return this->GetFunctor().GetReferencePixel();
+}
 
 }
 
diff --git a/Code/FeatureExtraction/otbCloudDetectionFunctor.h b/Code/FeatureExtraction/otbCloudDetectionFunctor.h
new file mode 100644
index 0000000000..edb58028a6
--- /dev/null
+++ b/Code/FeatureExtraction/otbCloudDetectionFunctor.h
@@ -0,0 +1,125 @@
+/*=========================================================================
+
+  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 __otbCloudDetectionFunctor_h
+#define __otbCloudDetectionFunctor_h
+
+#include "otbMath.h"
+#include "otbSpectralAngleFunctor.h"
+
+namespace otb
+{
+  /** \class CloudDetectionFunctor
+   *  \brief This functor first computes the spectral angle according to a reference pixel.
+   *  \brief Then multiplies the result by a gaussian coefficient
+   *  \brief Binarise the image with a threshold
+   *  \brief And reverse the pixel values.
+   */
+namespace Functor
+{
+template<class TInput,class TOutputValue>
+class CloudDetectionFunctor
+{
+ public:
+  typedef SpectralAngleFunctor<TInput, TOutputValue> SpectralAngleFunctorType;
+
+  CloudDetectionFunctor()
+    { 
+      m_ReferencePixel.SetSize(4);
+      m_ReferencePixel.Fill(1);
+      m_RefNorm = 2.0;
+      m_Variance = 1.0;
+      m_Denom = 1.0;
+      m_Coef = 1.0;
+
+maxigauss = 0;
+maxi = 0;
+minigauss = 100000;
+mini = 100000;
+
+    };
+
+  ~CloudDetectionFunctor(){};
+  inline TOutputValue operator()(const TInput& inPix)
+    {
+
+      TOutputValue lOut;
+      double lRes = 0.0;
+      double lCurPixNorm = 0.0;
+      double lGaussianCoef = 1.0;
+
+      for (unsigned int i=0; i<std::min(inPix.Size(),m_ReferencePixel.Size()); i++)
+      {
+        lCurPixNorm += inPix[i]*inPix[i];
+      }
+      lCurPixNorm = vcl_sqrt(static_cast<double>(lCurPixNorm));
+      lGaussianCoef = m_Coef * vcl_exp(- vcl_pow(((lCurPixNorm-m_RefNorm)/m_RefNorm),2) / m_Denom ) ;
+      lRes =  lGaussianCoef * (M_PI-m_SpectralAngleFunctor(inPix));
+
+if (lGaussianCoef > maxigauss){ maxigauss=lGaussianCoef; std::cout <<"maxigauss" << maxigauss << std::endl;}
+if (lRes > maxi){ maxi=lRes; std::cout <<"maxi"<< maxi << std::endl;}
+
+if (lGaussianCoef < minigauss){ minigauss=lGaussianCoef; std::cout <<"minigauss"<< minigauss << std::endl;}
+if (lRes < mini){ mini=lRes; std::cout <<"mini"<< mini << std::endl;}
+
+//       lRes = ( (-1)*(lRes/M_PI) ) +1 ;
+
+      lOut = static_cast<TOutputValue>(lRes);
+      return lOut;
+
+    }
+
+  void SetReferencePixel( TInput ref )
+    { 
+      m_ReferencePixel = ref;
+      m_SpectralAngleFunctor.SetReferencePixel(ref);
+      m_RefNorm = 0.0;
+      for(unsigned int i = 0; i<ref.Size(); i++)
+    {
+      m_RefNorm += ref[i]*ref[i];
+    }
+      m_RefNorm = vcl_sqrt(static_cast<double>(m_RefNorm)); 
+    };
+  void SetVariance(double variance)
+    {
+      m_Variance = variance;
+      m_Denom = 2 * variance * variance;
+      m_Coef = 1/( variance * vcl_sqrt(2*M_PI) );
+    }
+
+  TInput GetReferencePixel(){ return m_ReferencePixel; };
+  double GetVariance(){ return m_Variance; };
+
+  
+ protected:
+  SpectralAngleFunctorType m_SpectralAngleFunctor;
+  TInput m_ReferencePixel;
+  double m_RefNorm;
+  double m_Variance;
+  double m_Denom;
+  double m_Coef;
+double  maxi;
+double maxigauss;
+double  mini;
+double minigauss;
+};
+
+} // end namespace functor
+} // end namespace otb
+
+
+#endif
diff --git a/Code/FeatureExtraction/otbCloudEstimatorFilter.h b/Code/FeatureExtraction/otbCloudEstimatorFilter.h
new file mode 100644
index 0000000000..5ba05ec53b
--- /dev/null
+++ b/Code/FeatureExtraction/otbCloudEstimatorFilter.h
@@ -0,0 +1,87 @@
+/*=========================================================================
+
+  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 __otbCloudEstimatorFilter_h
+#define __otbCloudEstimatorFilter_h
+
+#include "otbSpectralAngleFunctor.h"
+#include "itkUnaryFunctorImageFilter.h"
+
+namespace otb
+{
+/** \class CloudEstimatorFilter
+ * \brief Applies spectral angle functor to an image.
+ * \brief Multiplies by a gaussian coefficient
+ * \brief Applies a color reversal.
+ */
+template <class TInputImage, class TOutputImage, class TFunction = Functor::SpectralAngleFunctor< 
+                                          ITK_TYPENAME TInputImage::PixelType, ITK_TYPENAME TOutputImage::PixelType> >
+class ITK_EXPORT CloudEstimatorFilter : public itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, TFunction >
+{
+public:
+  /** Standard class typedefs. */
+  typedef CloudEstimatorFilter                          Self;
+  typedef typename itk::UnaryFunctorImageFilter < TInputImage, TOutputImage, TFunction > 
+                                                        Superclass;
+  typedef itk::SmartPointer<Self>                       Pointer;
+  typedef itk::SmartPointer<const Self>                 ConstPointer;
+
+  /** Method for creation through the object factory. */
+  itkNewMacro(Self);
+
+  /** Run-time type information (and related methods). */
+  itkTypeMacro(CloudEstimatorFilter,UnaryFunctorImageFilter);
+
+  /** Some convenient typedefs. */
+  typedef          TInputImage                    InputImageType;
+  typedef typename InputImageType::Pointer        InputImagePointer;
+  typedef typename InputImageType::PixelType      InputPixelType;
+  typedef          TOutputImage                   OutputImageType;
+  typedef typename OutputImageType::Pointer       OutputImagePointer;
+  typedef typename OutputImageType::RegionType    OutputImageRegionType;
+  typedef typename OutputImageType::PixelType     OutputPixelType;
+
+  /** Getters/Setters */
+  void SetReferencePixel( InputPixelType ref );
+  InputPixelType GetReferencePixel();
+  void SetVariance( double var );
+  double GetVariance();
+
+protected:
+  CloudEstimatorFilter();
+
+  virtual ~CloudEstimatorFilter(){};
+
+  virtual void BeforeThreadedGenerateData();
+
+  virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
+
+private:
+  CloudEstimatorFilter(const Self&); //purposely not implemented
+  void operator=(const Self&); //purposely not implemented
+
+
+};
+
+} // end namespace otb
+
+#ifndef OTB_MANUAL_INSTANTIATION
+#include "otbCloudEstimatorFilter.txx"
+#endif
+
+#endif
+
diff --git a/Code/FeatureExtraction/otbCloudEstimatorFilter.txx b/Code/FeatureExtraction/otbCloudEstimatorFilter.txx
new file mode 100644
index 0000000000..6fe556602f
--- /dev/null
+++ b/Code/FeatureExtraction/otbCloudEstimatorFilter.txx
@@ -0,0 +1,111 @@
+/*=========================================================================
+
+  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 __otbCloudEstimatorFilter_txx
+#define __otbCloudEstimatorFilter_txx
+
+#include "otbCloudEstimatorFilter.h"
+
+
+namespace otb
+{
+
+/**
+ * Constructor
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::CloudEstimatorFilter()
+{
+}
+
+/**
+ * Printself
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::PrintSelf(std::ostream& os, itk::Indent indent) const
+{
+  this->Superclass::PrintSelf(os,indent);
+}
+
+/**
+ * BeforeThreadedGenerateData
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::BeforeThreadedGenerateData()
+{
+  unsigned int ReferencePixelNumberOfBands = 0;
+  ReferencePixelNumberOfBands = this->GetReferencePixel().GetSize();
+
+  if ( ReferencePixelNumberOfBands != this->GetInput()->GetNumberOfComponentsPerPixel() )
+  {
+    itkExceptionMacro("The number of bands of the reference pixel is different from the number of bands of the input image. ");
+  }
+}
+
+/**
+ * SetVariance
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::SetVariance(double var)
+{
+  this->GetFunctor().SetVariance( var );
+}
+
+/**
+ * GetVariance
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+double
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::GetVariance()
+{
+  return this->GetFunctor().GetVariance();
+}
+
+/**
+ * SetReferencePixel
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+void
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::SetReferencePixel(InputPixelType ref)
+{
+  this->GetFunctor().SetReferencePixel( ref );
+}
+
+/**
+ * GetReferencePixel
+ */
+template <class TInputImage, class TOutputImage, class TFunction>
+typename CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>::InputPixelType
+CloudEstimatorFilter<TInputImage,TOutputImage,TFunction>
+::GetReferencePixel()
+{
+  return this->GetFunctor().GetReferencePixel();
+}
+
+}
+
+#endif
+
diff --git a/Code/FeatureExtraction/otbCloudEstimatorFunctor.h b/Code/FeatureExtraction/otbCloudEstimatorFunctor.h
new file mode 100644
index 0000000000..b16850c360
--- /dev/null
+++ b/Code/FeatureExtraction/otbCloudEstimatorFunctor.h
@@ -0,0 +1,125 @@
+/*=========================================================================
+
+  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 __otbCloudEstimatorFunctor_h
+#define __otbCloudEstimatorFunctor_h
+
+#include "otbMath.h"
+#include "otbSpectralAngleFunctor.h"
+
+namespace otb
+{
+  /** \class CloudEstimatorFunctor
+   *  \brief This functor first computes the spectral angle according to a reference pixel.
+   *  \brief Then multiplies the result by a gaussian coefficient
+   *  \brief Binarise the image with a threshold
+   *  \brief And reverse the pixel values.
+   */
+namespace Functor
+{
+template<class TInput,class TOutputValue>
+class CloudEstimatorFunctor
+{
+ public:
+  typedef SpectralAngleFunctor<TInput, TOutputValue> SpectralAngleFunctorType;
+
+  CloudEstimatorFunctor()
+    { 
+      m_ReferencePixel.SetSize(4);
+      m_ReferencePixel.Fill(1);
+      m_RefNorm = 2.0;
+      m_Variance = 1.0;
+      m_Denom = 1.0;
+      m_Coef = 1.0;
+
+maxigauss = 0;
+maxi = 0;
+minigauss = 100000;
+mini = 100000;
+
+    };
+
+  ~CloudEstimatorFunctor(){};
+  inline TOutputValue operator()(const TInput& inPix)
+    {
+
+      TOutputValue lOut;
+      double lRes = 0.0;
+      double lCurPixNorm = 0.0;
+      double lGaussianCoef = 1.0;
+
+      for (unsigned int i=0; i<std::min(inPix.Size(),m_ReferencePixel.Size()); i++)
+      {
+        lCurPixNorm += inPix[i]*inPix[i];
+      }
+      lCurPixNorm = vcl_sqrt(static_cast<double>(lCurPixNorm));
+      lGaussianCoef = m_Coef * vcl_exp(- vcl_pow(((lCurPixNorm-m_RefNorm)/m_RefNorm),2) / m_Denom ) ;
+      lRes =  lGaussianCoef * (M_PI-m_SpectralAngleFunctor(inPix));
+
+if (lGaussianCoef > maxigauss){ maxigauss=lGaussianCoef; std::cout << maxigauss << std::endl;}
+if (lRes > maxi){ maxi=lRes; std::cout << maxi << std::endl;}
+
+if (lGaussianCoef < minigauss){ minigauss=lGaussianCoef; std::cout << minigauss << std::endl;}
+if (lRes < mini){ mini=lRes; std::cout << mini << std::endl;}
+
+//       lRes = ( (-1)*(lRes/M_PI) ) +1 ;
+
+      lOut = static_cast<TOutputValue>(lRes);
+      return lOut;
+
+    }
+
+  void SetReferencePixel( TInput ref )
+    { 
+      m_ReferencePixel = ref;
+      m_SpectralAngleFunctor.SetReferencePixel(ref);
+      m_RefNorm = 0.0;
+      for(unsigned int i = 0; i<ref.Size(); i++)
+    {
+      m_RefNorm += ref[i]*ref[i];
+    }
+      m_RefNorm = vcl_sqrt(static_cast<double>(m_RefNorm)); 
+    };
+  void SetVariance(double variance)
+    {
+      m_Variance = variance;
+      m_Denom = 2 * variance * variance;
+      m_Coef = 1/( variance * vcl_sqrt(2*M_PI) );
+    }
+
+  TInput GetReferencePixel(){ return m_ReferencePixel; };
+  double GetVariance(){ return m_Variance; };
+
+  
+ protected:
+  SpectralAngleFunctorType m_SpectralAngleFunctor;
+  TInput m_ReferencePixel;
+  double m_RefNorm;
+  double m_Variance;
+  double m_Denom;
+  double m_Coef;
+double  maxi;
+double maxigauss;
+double  mini;
+double minigauss;
+};
+
+} // end namespace functor
+} // end namespace otb
+
+
+#endif
diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt
index cc8cb023d6..26fa53e0be 100644
--- a/Testing/Code/FeatureExtraction/CMakeLists.txt
+++ b/Testing/Code/FeatureExtraction/CMakeLists.txt
@@ -980,27 +980,53 @@ ADD_TEST(feTuLandmarkNew ${FEATUREEXTRACTION_TESTS10}
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 
 
-# -------            otb::CloudDetectionFilterNew   -------------
-ADD_TEST(feTuCloudDetectionFilterNew ${FEATUREEXTRACTION_TESTS11} 
-    otbCloudDetectionFilterNew)
+# -------            otb::CloudEstimatorFilterNew   -------------
+ADD_TEST(feTuCloudEstimatorFilterNew ${FEATUREEXTRACTION_TESTS11} 
+    otbCloudEstimatorFilterNew)
 
-ADD_TEST(feTvCloudDetectionFilter ${FEATUREEXTRACTION_TESTS11} 
+ADD_TEST(feTvCloudEstimatorDefaultFilter ${FEATUREEXTRACTION_TESTS11} 
 --compare-image ${EPS}
      ${BASELINE}/feTvSpectralAngleOutput.tif
      ${TEMP}/feTvSpectralAngleOutput.tif
-    otbCloudDetectionFilter
+    otbCloudEstimatorDefaultFilter
     ${INPUTDATA}/ExtrZoneNuageuse.tif
     ${TEMP}/feTvSpectralAngleOutput.tif
     500
     731
     500
     632
-    1    # variance
-    1000 # threshold
 )
 
+ADD_TEST(feTvCloudEstimatorFilter ${FEATUREEXTRACTION_TESTS11} 
+--compare-image ${EPS}
+     ${BASELINE}/feTvCloudEstimatorOutput.tif
+     ${TEMP}/feTvCloudEstimatorOutput.tif
+    otbCloudEstimatorFilter
+    ${INPUTDATA}/ExtrZoneNuageuse.tif
+    ${TEMP}/feTvCloudEstimatorOutput.tif
+    500
+    731
+    500
+    632
+    10    # variance
+)
 
+# -------            otb::CloudDetectionFilterNew   -------------
 
+# ADD_TEST(feTvCloudEstimatorFilter ${FEATUREEXTRACTION_TESTS11} 
+# --compare-image ${EPS}
+#      ${BASELINE}/feTvCloudDetectionOutput.tif
+#      ${TEMP}/feTvCloudDetectionOutput.tif
+#     otbCloudDetectionFilter
+#     ${INPUTDATA}/ExtrZoneNuageuse.tif
+#     ${TEMP}/feTvCloudDetectionOutput.tif
+#     500
+#     731
+#     500
+#     632
+#     10    # variance
+#     10    # threshold
+# )
 
 
 # A enrichir
@@ -1127,8 +1153,11 @@ otbKeyPointSetsMatchingFilter.cxx
 otbLandmarkNew.cxx
 )
 SET(BasicFeatureExtraction_SRCS11
-otbCloudDetectionFilterNew.cxx
-otbCloudDetectionFilter.cxx
+otbCloudEstimatorFilterNew.cxx
+otbCloudEstimatorDefaultFilter.cxx
+otbCloudEstimatorFilter.cxx
+#otbCloudDetectionFilterNew.cxx
+#otbCloudDetectionFilter.cxx
 )
 
 INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
diff --git a/Testing/Code/FeatureExtraction/otbCloudEstimatorDefaultFilter.cxx b/Testing/Code/FeatureExtraction/otbCloudEstimatorDefaultFilter.cxx
new file mode 100644
index 0000000000..f4f4be9089
--- /dev/null
+++ b/Testing/Code/FeatureExtraction/otbCloudEstimatorDefaultFilter.cxx
@@ -0,0 +1,71 @@
+/*=========================================================================
+
+  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 "itkExceptionObject.h"
+
+#include "otbVectorImage.h"
+#include "otbImage.h"
+#include "otbSpectralAngleFunctor.h"
+#include "otbCloudEstimatorFilter.h"
+#include "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+
+
+int otbCloudEstimatorDefaultFilter(int argc, char * argv[])
+{
+  const unsigned int Dimension                                                   = 2;
+  typedef double                                                                 PixelType;
+  typedef otb::VectorImage<PixelType,Dimension>                                  VectorImageType;
+  typedef otb::Image<PixelType,Dimension>                                        ImageType;
+  typedef VectorImageType::PixelType                                             VectorPixelType;
+  typedef otb::CloudEstimatorFilter<VectorImageType,ImageType >                  CloudEstimatorFilterType;
+  typedef otb::ImageFileReader<VectorImageType>                                  ReaderType;
+  typedef otb::ImageFileWriter<ImageType>                                        WriterType;
+
+  //Parameters
+  const char * inputFileName(argv[1]);
+  const char * outputFileName(argv[2]);
+  VectorPixelType referencePixel;
+  referencePixel.SetSize(4);
+  referencePixel.Fill(0.);
+
+  referencePixel[0] = (atof(argv[3]));
+  referencePixel[1] = (atof(argv[4]));
+  referencePixel[2] = (atof(argv[5]));
+  referencePixel[3] = (atof(argv[6]));
+
+
+  // Instantiating object
+  ReaderType::Pointer reader = ReaderType::New();
+
+  // Using SpectralAngle Filter, the default functor
+  CloudEstimatorFilterType::Pointer cloudEstimator = CloudEstimatorFilterType::New();
+  WriterType::Pointer writer = WriterType::New();
+
+  //Initialisation parameters
+  reader->SetFileName(inputFileName);
+
+  cloudEstimator->SetInput(reader->GetOutput());
+  cloudEstimator->SetReferencePixel(referencePixel);
+
+  writer->SetFileName(outputFileName);
+  writer->SetInput(cloudEstimator->GetOutput());
+  writer->Update();
+
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/FeatureExtraction/otbCloudEstimatorFilter.cxx b/Testing/Code/FeatureExtraction/otbCloudEstimatorFilter.cxx
new file mode 100644
index 0000000000..8f21567c4c
--- /dev/null
+++ b/Testing/Code/FeatureExtraction/otbCloudEstimatorFilter.cxx
@@ -0,0 +1,73 @@
+/*=========================================================================
+
+  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 "itkExceptionObject.h"
+
+#include "otbVectorImage.h"
+#include "otbImage.h"
+#include "otbCloudEstimatorFunctor.h"
+#include "otbCloudEstimatorFilter.h"
+#include "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+
+
+int otbCloudEstimatorFilter(int argc, char * argv[])
+{
+  const unsigned int Dimension                                                   = 2;
+  typedef double                                                                 PixelType;
+  typedef otb::VectorImage<PixelType,Dimension>                                  VectorImageType;
+  typedef otb::Image<PixelType,Dimension>                                        ImageType;
+  typedef VectorImageType::PixelType                                             VectorPixelType;
+  typedef otb::Functor::CloudEstimatorFunctor<VectorPixelType,PixelType >        FunctorType;
+  typedef otb::CloudEstimatorFilter<VectorImageType,ImageType,FunctorType >      CloudEstimatorFilterType;
+  typedef otb::ImageFileReader<VectorImageType>                                  ReaderType;
+  typedef otb::ImageFileWriter<ImageType>                                        WriterType;
+
+  //Parameters
+  const char * inputFileName(argv[1]);
+  const char * outputFileName(argv[2]);
+  VectorPixelType referencePixel;
+  referencePixel.SetSize(4);
+  referencePixel.Fill(0.);
+
+  referencePixel[0] = (atof(argv[3]));
+  referencePixel[1] = (atof(argv[4]));
+  referencePixel[2] = (atof(argv[5]));
+  referencePixel[3] = (atof(argv[6]));
+
+  const double variance = (atof(argv[7]));
+
+ // Instantiating object
+  ReaderType::Pointer reader = ReaderType::New();
+  CloudEstimatorFilterType::Pointer cloudEstimator = CloudEstimatorFilterType::New();
+  WriterType::Pointer writer = WriterType::New();
+
+  //Initialisation parameters
+  reader->SetFileName(inputFileName);
+
+  cloudEstimator->SetInput(reader->GetOutput());
+  cloudEstimator->SetReferencePixel(referencePixel);
+  cloudEstimator->SetVariance(variance);
+
+
+  writer->SetFileName(outputFileName);
+  writer->SetInput(cloudEstimator->GetOutput());
+  writer->Update();
+
+  return EXIT_SUCCESS;
+
+}
diff --git a/Testing/Code/FeatureExtraction/otbCloudEstimatorFilterNew.cxx b/Testing/Code/FeatureExtraction/otbCloudEstimatorFilterNew.cxx
new file mode 100644
index 0000000000..0481e21271
--- /dev/null
+++ b/Testing/Code/FeatureExtraction/otbCloudEstimatorFilterNew.cxx
@@ -0,0 +1,36 @@
+/*=========================================================================
+
+  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 "otbImage.h"
+#include "otbVectorImage.h"
+#include "otbCloudEstimatorFilter.h"
+
+int otbCloudEstimatorFilterNew(int argc, char * argv[])
+{
+  const unsigned int Dimension                                  = 2;
+  typedef double                                                PixelType;
+  typedef otb::Image<PixelType,Dimension>                       ImageType;
+  typedef otb::VectorImage<PixelType,Dimension>                 VectorImageType;
+  typedef otb::CloudEstimatorFilter<VectorImageType,ImageType > CloudEstimatorFilterType;
+
+
+  // Instantiating object
+  CloudEstimatorFilterType::Pointer cloudEstimator = CloudEstimatorFilterType::New();
+
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx
index 00f52bf021..f4b0f39a48 100644
--- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx
+++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests11.cxx
@@ -27,6 +27,9 @@
 
 void RegisterTests()
 {
-REGISTER_TEST(otbCloudDetectionFilterNew);
-REGISTER_TEST(otbCloudDetectionFilter);
+REGISTER_TEST(otbCloudEstimatorFilterNew);
+REGISTER_TEST(otbCloudEstimatorDefaultFilter);
+REGISTER_TEST(otbCloudEstimatorFilter);
+/*REGISTER_TEST(otbCloudDetectionFilterNew);
+REGISTER_TEST(otbCloudDetectionFilter);*/
 }
-- 
GitLab