From 2de129331ce2584214f2a74b818b7a520055c6c0 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Wed, 18 Oct 2017 09:58:14 +0200
Subject: [PATCH] TEST : new test for compute histo filter

---
 .../include/otbComputeHistoFilter.txx         |  2 +-
 .../Filtering/Contrast/test/CMakeLists.txt    |  1 +
 .../Contrast/test/otbComputeHistoFilter.cxx   | 61 +++++++++++++++++++
 .../Contrast/test/otbContrastTestDriver.cxx   |  1 +
 4 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/Modules/Filtering/Contrast/include/otbComputeHistoFilter.txx b/Modules/Filtering/Contrast/include/otbComputeHistoFilter.txx
index af4476251a..6d306a6d17 100644
--- a/Modules/Filtering/Contrast/include/otbComputeHistoFilter.txx
+++ b/Modules/Filtering/Contrast/include/otbComputeHistoFilter.txx
@@ -280,7 +280,7 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
       oit.Get()[i] = agreg;
       total += agreg;
       }
-    if ( m_Threshold != -1 )
+    if ( m_Threshold > 0 )
       ApplyThreshold( oit , total );
     }
 }
diff --git a/Modules/Filtering/Contrast/test/CMakeLists.txt b/Modules/Filtering/Contrast/test/CMakeLists.txt
index a3f1dce75e..0e7d88e331 100644
--- a/Modules/Filtering/Contrast/test/CMakeLists.txt
+++ b/Modules/Filtering/Contrast/test/CMakeLists.txt
@@ -23,6 +23,7 @@ otb_module_test()
 set(OTBContrastTests
 otbContrastTestDriver.cxx
 otbComputeHistoFilterNew.cxx
+otbComputeHistoFilter.cxx
 otbApplyGainFilterNew.cxx
 otbComputeGainLutFilterNew.cxx
 otbCLHistogramEqualizationFilterNew.cxx
diff --git a/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx b/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx
index e69de29bb2..db5deeeebf 100644
--- a/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx
+++ b/Modules/Filtering/Contrast/test/otbComputeHistoFilter.cxx
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
+ *
+ * This file is part of Orfeo Toolbox
+ *
+ *     https://www.orfeo-toolbox.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "otbImage.h"
+#include "otbImageFileWriter.h"
+#include "otbImageFileReader.h"
+#include "otbVectorImage.h"
+#include "otbComputeHistoFilter.h"
+
+int otbComputeHistoFilter(int itkNotUsed(argc), char * itkNotUsed(argv) [])
+{
+  typedef int InputPixelType;
+  typedef int OutputPixelType;
+  const unsigned int Dimension = 2;
+
+  typedef otb::Image< InputPixelType ,  Dimension > InputImageType;
+  typedef otb::VectorImage< OutputPixelType , Dimension > HistoImageType;
+  typedef otb::ComputeHistoFilter< InputImageType , HistoImageType > FilterType;
+
+  typedef otb::ImageFileReader< InputImageType > ReaderType; 
+  typedef otb::ImageFileWriter< HistoImageType > WriterType;
+  ReaderType::Pointer reader ( ReaderType::New() );
+  WriterType::Pointer writer ( WriterType::New() );
+  reader->SetFileName( "/home/antoine/dev/my_data/test/smallinput.tif" );
+  writer->SetFileName( "/home/antoine/dev/my_data/test/small_glob_histo.tif" );
+  reader->UpdateOutputInformation();
+
+  FilterType::Pointer computeHisto ( FilterType::New() );
+  
+  computeHisto->SetInput( reader->GetOutput() );
+  computeHisto->SetMin(0);
+  computeHisto->SetMax(255);
+  computeHisto->SetNbBin(256);
+  // computeHisto->SetThreshol(256);
+  auto size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
+  computeHisto->SetThumbSize(size);
+
+  writer->SetInput( computeHisto->GetHistoOutput() );
+  writer->Update();
+  auto index = computeHisto->GetHistoOutput()->GetLargestPossibleRegion().GetIndex();
+  std::cout << computeHisto->GetHistoOutput()->GetPixel(index) << std::endl;
+
+  return EXIT_SUCCESS;
+}
\ No newline at end of file
diff --git a/Modules/Filtering/Contrast/test/otbContrastTestDriver.cxx b/Modules/Filtering/Contrast/test/otbContrastTestDriver.cxx
index 5e8714682d..4a4311f598 100644
--- a/Modules/Filtering/Contrast/test/otbContrastTestDriver.cxx
+++ b/Modules/Filtering/Contrast/test/otbContrastTestDriver.cxx
@@ -23,6 +23,7 @@
 void RegisterTests()
 {
   REGISTER_TEST(otbComputeHistoFilterNew);
+  REGISTER_TEST(otbComputeHistoFilter);
   REGISTER_TEST(otbComputeGainLutFilterNew);
   REGISTER_TEST(otbApplyGainFilterNew);
   REGISTER_TEST(otbCLHistogramEqualizationFilterNew);
-- 
GitLab