From 6797c75f038b86f3574015d0c5a4ed21e1233eb9 Mon Sep 17 00:00:00 2001
From: Aurelien Bricier <aurelien.bricier@c-s.fr>
Date: Fri, 19 Nov 2010 11:26:08 +0100
Subject: [PATCH] ENH: changed negative sample position generation
 parametrization

---
 .../otbLabeledSampleLocalizationGenerator.h   |  5 +++++
 .../otbLabeledSampleLocalizationGenerator.txx | 20 ++++++++++---------
 .../otbLabeledSampleLocalizationGenerator.cxx |  3 ++-
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h
index 76404b2b05..0f4eeaea00 100644
--- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h
+++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.h
@@ -96,6 +96,10 @@ public:
   itkGetConstMacro(InhibitionRadius, double);
   itkSetMacro(InhibitionRadius, double);
 
+  /** The maximum iteration number during negative sample positions */
+  itkGetConstMacro(NbMaxIteration, unsigned long int);
+  itkSetMacro(NbMaxIteration, unsigned long int);
+
   /** Set the seed for random number generator */
   void SetSeed(unsigned int seed)
   {
@@ -122,6 +126,7 @@ private:
   int                       m_NoClassIdentifier;
   double                    m_RandomLocalizationDensity;
   double                    m_InhibitionRadius;
+  unsigned long int         m_NbMaxIteration;
 };
 
 } // end namespace otb
diff --git a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx
index 8b31036d6f..cfa68e0eeb 100644
--- a/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx
+++ b/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.txx
@@ -29,8 +29,9 @@ LabeledSampleLocalizationGenerator<TVectorData>
 ::LabeledSampleLocalizationGenerator() :
   m_ClassKey("Class"),
   m_NoClassIdentifier(0),
-  m_RandomLocalizationDensity(.05),
-  m_InhibitionRadius(5.0)
+  m_RandomLocalizationDensity(.005),
+  m_InhibitionRadius(5.0),
+  m_NbMaxIteration(10000)
 {
   this->SetNumberOfRequiredInputs(1);
   this->SetNumberOfRequiredOutputs(1);
@@ -114,16 +115,17 @@ LabeledSampleLocalizationGenerator<TVectorData>
   //std::cout << "insiders: " << insiders.size() << std::endl;
 
   // Search parametrization 
-  unsigned int nbMaxIter = (unsigned int)(node->GetPolygonExteriorRing()->GetArea());
-//                                           - insiders.size() * CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2))
-//                                           / (CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2)));
-  //std::cout << "nbMaxIter: " << nbMaxIter << std::endl;
-
-  unsigned int nbMaxPosition = (unsigned int)(nbMaxIter * this->GetRandomLocalizationDensity());
+  //unsigned int nbMaxIter = (unsigned int)(node->GetPolygonExteriorRing()->GetArea());
+  //                                         - insiders.size() * CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2))
+  //                                         / (CONST_PI * vcl_pow(this->GetInhibitionRadius(), 2)));
+  
+  unsigned int nbMaxPosition = (unsigned int)(node->GetPolygonExteriorRing()->GetArea() * this->GetRandomLocalizationDensity());
+  
+  //std::cout << "nbMaxIter: " << this->GetNbMaxIteration() << std::endl;
   //std::cout << "nbMaxPosition: " << nbMaxPosition << std::endl;
   
   // Generation
-  unsigned int nbIter =  nbMaxIter;
+  unsigned long int nbIter =  this->GetNbMaxIteration();
   unsigned int nbPosition = nbMaxPosition;
 
   PointType rangeMin,rangeMax;
diff --git a/Testing/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.cxx b/Testing/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.cxx
index cac3d605d6..08d91bda76 100644
--- a/Testing/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.cxx
+++ b/Testing/Code/ObjectDetection/otbLabeledSampleLocalizationGenerator.cxx
@@ -67,7 +67,8 @@ int otbLabeledSampleLocalizationGenerator(int argc, char* argv[])
   generator->SetClassKey("Class");
   generator->SetNoClassIdentifier(0);
   generator->SetInhibitionRadius(5);
-  generator->SetRandomLocalizationDensity(0.05);
+  generator->SetRandomLocalizationDensity(0.004);
+  generator->SetNbMaxIteration(1000);
 
   generator->Update();
 
-- 
GitLab