From 5e861a2de7355b953e22e809daaf8dd3614e0f7c Mon Sep 17 00:00:00 2001 From: Jordi Inglada <jordi.inglada@cesbio.cnes.fr> Date: Wed, 21 Oct 2015 14:49:49 +0200 Subject: [PATCH] ENH: tidy up CvRTreesWrapper and add comments --- .../Supervised/include/otbCvRTreesWrapper.h | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h b/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h index 6175b1f462..47f4560293 100644 --- a/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h +++ b/Modules/Learning/Supervised/include/otbCvRTreesWrapper.h @@ -20,13 +20,29 @@ #include "otbOpenCVUtils.h" #include <vector> +#include <algorithm> + +namespace otb +{ + +/** \class CvRTreesWrapper + * \brief Wrapper for OpenCV Random Trees + * + * \ingroup OTBSupervised + */ class CV_EXPORTS_W CvRTreesWrapper : public CvRTrees { public: CvRTreesWrapper(){}; virtual ~CvRTreesWrapper(){}; + /** Predict the confidence of the classifcation by computing the + difference in votes between the first and second most voted classes. + This measure is preferred to the proportion of votes of the majority + class, since it provides information about the conflict between the + most likely classes. + */ float predict_confidence(const cv::Mat& sample, const cv::Mat& missing = cv::Mat()) const @@ -39,16 +55,15 @@ public: CV_Assert( 0 <= class_idx && class_idx < nclasses ); ++classVotes[class_idx]; } + // We only sort the 2 greatest elements std::nth_element(classVotes.begin(), classVotes.begin()+1, classVotes.end(), std::greater<>()); - unsigned int maxVotes = classVotes[0]; - unsigned int secondVotes = classVotes[1]; - float confidence = static_cast<float>(maxVotes-secondVotes)/ntrees; + float confidence = static_cast<float>(classVotes[0]-classVotes[1])/ntrees; return confidence; }; }; - +} #endif -- GitLab