From 0bd24f4472e38b9558597677c5e67297823e3f06 Mon Sep 17 00:00:00 2001
From: Jonathan Guinet <jonathan.guinet@c-s.fr>
Date: Tue, 20 Mar 2012 11:41:56 +0100
Subject: [PATCH] TEST: MeanShifttConnectedComponentSegmentationFilter tests .
 WIP.

---
 Testing/Code/OBIA/CMakeLists.txt              |  18 ++-
 ...nnectedComponentSegmentationFilterTest.cxx | 110 ++++++++++++++++++
 Testing/Code/OBIA/otbOBIATests1.cxx           |   1 +
 3 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 Testing/Code/OBIA/otbMeanShiftConnectedComponentSegmentationFilterTest.cxx

diff --git a/Testing/Code/OBIA/CMakeLists.txt b/Testing/Code/OBIA/CMakeLists.txt
index b62edac236..295ac8ab62 100644
--- a/Testing/Code/OBIA/CMakeLists.txt
+++ b/Testing/Code/OBIA/CMakeLists.txt
@@ -148,7 +148,7 @@ ADD_TEST(obTvStreamingConnectedComponentSegmentationOBIAToVectorDataFilter ${OBI
       "SHAPE_Elongation>8"
       5 )
 
-#TODO add validation test
+#TODO JGT add validation test
 ADD_TEST(obTuMeanShiftStreamingConnectedComponentSegmentationOBIAToVectorDataFilter ${OBIA_TESTS1}
       otbMeanShiftStreamingConnectedComponentSegmentationOBIAToVectorDataFilter
       ${INPUTDATA}/ROI_QB_MUL_4.tif
@@ -164,6 +164,21 @@ ADD_TEST(obTuMeanShiftStreamingConnectedComponentSegmentationOBIAToVectorDataFil
       "SHAPE_Elongation>10"
       5 )
 
+#TODO JGT add validation test
+ADD_TEST(obTuMeanShiftConnectedComponentSegmentationFilter ${OBIA_TESTS1}
+      otbMeanShiftConnectedComponentSegmentationFilter
+      ${INPUTDATA}/ROI_QB_MUL_4.tif
+      ${TEMP}/obTuMeanShiftConnectedComponentSegmentationImage.png
+      9 
+      9 
+      50 
+      10 
+      0.001
+      ""
+      "distance<0.2"
+      20)
+      
+
 
 
 ADD_TEST(obTuLabelImageToLabelMapWithAdjacencyFilterNew ${OBIA_TESTS3}
@@ -289,6 +304,7 @@ otbVectorDataToLabelMapFilter.cxx
 otbVectorDataToLabelMapFilterNew.cxx
 otbStreamingConnectedComponentOBIATest.cxx
 otbMeanShiftStreamingConnectedComponentOBIATest.cxx
+otbMeanShiftConnectedComponentSegmentationFilterTest.cxx
 otbHooverMatrixFilterNew.cxx
 otbHooverMatrixFilter.cxx
 otbHooverInstanceFilterNew.cxx
diff --git a/Testing/Code/OBIA/otbMeanShiftConnectedComponentSegmentationFilterTest.cxx b/Testing/Code/OBIA/otbMeanShiftConnectedComponentSegmentationFilterTest.cxx
new file mode 100644
index 0000000000..4fdac54400
--- /dev/null
+++ b/Testing/Code/OBIA/otbMeanShiftConnectedComponentSegmentationFilterTest.cxx
@@ -0,0 +1,110 @@
+/*=========================================================================
+
+  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 "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+#include "otbMeanShiftImageFilter2.h"
+#include "otbMeanShiftConnectedComponentSegmentationFilter.h"
+
+typedef float InputPixelType;
+const unsigned int Dimension = 2;
+typedef double                                          KernelType;
+typedef otb::Image<unsigned int, Dimension>             LabelImageType;
+typedef otb::Image<unsigned int, Dimension>             MaskImageType;
+
+
+typedef otb::VectorImage<InputPixelType, Dimension>     ImageType;
+typedef otb::ImageFileReader<ImageType>                 ReaderType;
+typedef otb::ImageFileWriter<LabelImageType>            WriterType;
+
+
+typedef otb::MeanShiftConnectedComponentSegmentationFilter
+  < ImageType, MaskImageType,
+    LabelImageType >  MeanShiftConnectedComponentsegmentationFilterType;
+
+typedef otb::MeanShiftImageFilter2<ImageType, ImageType,ImageType,KernelType> MeanShiftFilterType;
+
+
+int otbMeanShiftConnectedComponentSegmentationFilter(int argc, char * argv[])
+{
+
+  /* mean shift parameters */
+
+  const char * infname = argv[1];
+  const char * outputFilename = argv[2];
+
+  /* mean shift parameters */
+  const unsigned int spatialRadius = atoi(argv[3]);
+  const unsigned int spectralRadius = atoi(argv[4]);
+  const double spectralbandwidth = atof(argv[5]);
+  const double spatialbandwidth = atof(argv[6]);
+  const double threshold = atof(argv[7]);
+
+  /* conencted component parameters */
+
+  const char * maskexpression = argv[8];
+  const char * segmentationexpression = argv[9];
+  unsigned int minobjectsize = atoi(argv[10]);
+
+   // add meanshift options
+
+
+  // Instantiating object
+  MeanShiftFilterType::Pointer meanShiftFilter = MeanShiftFilterType::New();
+  MeanShiftConnectedComponentsegmentationFilterType::Pointer segmentationFilter= MeanShiftConnectedComponentsegmentationFilterType::New();
+  ReaderType::Pointer reader = ReaderType::New();
+  WriterType::Pointer writer = WriterType::New();
+
+  reader->SetFileName(infname);
+
+  //define square radius
+  ImageType::SizeType radius;
+  radius[0] = spatialRadius;
+  radius[1] = spatialRadius;
+
+  meanShiftFilter->SetSpatialRadius(radius);
+
+  radius[0] = spectralRadius;
+  radius[1] = spectralRadius;
+  meanShiftFilter->SetRangeRadius(radius);
+  meanShiftFilter->SetSpectralBandwidth(spectralbandwidth);
+  meanShiftFilter->SetSpatialBandwidth(spatialbandwidth);
+  meanShiftFilter->SetThreshold(threshold);
+
+  meanShiftFilter->SetInput(reader->GetOutput());
+  meanShiftFilter->GetRangeOutput();
+
+  // set the mean shift filter
+  segmentationFilter->SetMeanShiftFilter(meanShiftFilter);
+
+
+  segmentationFilter->SetInput(meanShiftFilter->GetRangeOutput());
+
+  segmentationFilter->SetMaskExpression(maskexpression);
+  segmentationFilter->SetConnectedComponentExpression(segmentationexpression);
+  segmentationFilter->SetMinimumObjectSize(minobjectsize);
+
+  //segmentationFilter->Update();
+
+ writer->SetInput(segmentationFilter->GetOutput());
+ writer->SetFileName(outputFilename);
+ writer->Update();
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/OBIA/otbOBIATests1.cxx b/Testing/Code/OBIA/otbOBIATests1.cxx
index c98139c748..d1254ae3ac 100644
--- a/Testing/Code/OBIA/otbOBIATests1.cxx
+++ b/Testing/Code/OBIA/otbOBIATests1.cxx
@@ -54,6 +54,7 @@ REGISTER_TEST(otbVectorDataToLabelMapFilter);
 REGISTER_TEST(otbStreamingConnectedComponentSegmentationOBIAToVectorDataFilterNew);
 REGISTER_TEST(otbStreamingConnectedComponentSegmentationOBIAToVectorDataFilter);
 REGISTER_TEST(otbMeanShiftStreamingConnectedComponentSegmentationOBIAToVectorDataFilter);
+REGISTER_TEST(otbMeanShiftConnectedComponentSegmentationFilter);
 REGISTER_TEST(otbHooverMatrixFilterNew);
 REGISTER_TEST(otbHooverMatrixFilter);
 REGISTER_TEST(otbHooverInstanceFilterNew);
-- 
GitLab