From c0aa9bd39bc800890b465564b78f6aa4002df2af Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Wed, 17 Oct 2012 00:54:30 +0200 Subject: [PATCH] ENH: ListSampleGenerator, reorganize code, remove a useless member --- Code/Learning/otbListSampleGenerator.h | 1 - Code/Learning/otbListSampleGenerator.txx | 54 ++++++++++-------------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Code/Learning/otbListSampleGenerator.h b/Code/Learning/otbListSampleGenerator.h index a49c4d05b2..7bb91e3ed9 100644 --- a/Code/Learning/otbListSampleGenerator.h +++ b/Code/Learning/otbListSampleGenerator.h @@ -170,7 +170,6 @@ private: // useful, when dealing with small polygon area (1 or two pixels) // false by default std::string m_ClassKey; - double m_ClassMinSize; ListSamplePointerType m_TrainingListSample; ListLabelPointerType m_TrainingListLabel; diff --git a/Code/Learning/otbListSampleGenerator.txx b/Code/Learning/otbListSampleGenerator.txx index f022a98079..033d1c90be 100644 --- a/Code/Learning/otbListSampleGenerator.txx +++ b/Code/Learning/otbListSampleGenerator.txx @@ -65,8 +65,7 @@ ListSampleGenerator<TImage, TVectorData> m_MaxValidationSize(-1), m_ValidationTrainingProportion(0.0), m_PolygonEdgeInclusion(false), - m_ClassKey("Class"), - m_ClassMinSize(-1) + m_ClassKey("Class") { this->SetNumberOfRequiredInputs(2); this->SetNumberOfRequiredOutputs(1); @@ -263,27 +262,6 @@ ListSampleGenerator<TImage, TVectorData> } } - // Compute the class with the minimum number of pixels - if (!m_ClassesSize.empty()) - { - double minSize = itk::NumericTraits<double>::max(); - - for (std::map<ClassLabelType, double>::const_iterator itmap = m_ClassesSize.begin(); - itmap != m_ClassesSize.end(); - ++itmap) - { - if (minSize > itmap->second) - { - minSize = itmap->second; - } - } - - m_ClassMinSize = minSize; - } - else - { - itkGenericExceptionMacro(<< "No training sample found inside image") - } } template <class TImage, class TVectorData> @@ -293,16 +271,30 @@ ListSampleGenerator<TImage, TVectorData> { m_ClassesProbTraining.clear(); m_ClassesProbValidation.clear(); + + // Sanity check + if (m_ClassesSize.empty()) + { + itkGenericExceptionMacro(<< "No training sample found inside image"); + } - //Go through the classes size to find the smallest one - double minSizeTraining = m_ClassMinSize; - double minSizeValidation = minSizeTraining; + // Go through the classes size to find the smallest one + double minSize = itk::NumericTraits<double>::max(); + for (std::map<ClassLabelType, double>::const_iterator itmap = m_ClassesSize.begin(); + itmap != m_ClassesSize.end(); + ++itmap) + { + if (minSize > itmap->second) + { + minSize = itmap->second; + } + } - //Apply the proportion between training and validation samples (all training by default) - minSizeTraining *= (1.0 - m_ValidationTrainingProportion); - minSizeValidation *= m_ValidationTrainingProportion; + // Apply the proportion between training and validation samples (all training by default) + double minSizeTraining = minSize * (1.0 - m_ValidationTrainingProportion); + double minSizeValidation = minSize * m_ValidationTrainingProportion; - //Apply the limit if specified by the user + // Apply the limit if specified by the user if ((m_MaxTrainingSize != -1) && (m_MaxTrainingSize < minSizeTraining)) { minSizeTraining = m_MaxTrainingSize; @@ -312,7 +304,7 @@ ListSampleGenerator<TImage, TVectorData> minSizeValidation = m_MaxValidationSize; } - //Compute the probability selection for each class + // Compute the probability selection for each class for (std::map<ClassLabelType, double>::const_iterator itmap = m_ClassesSize.begin(); itmap != m_ClassesSize.end(); ++itmap) -- GitLab