Making CvEM predict() return probabilities (Patch #964)
Description
Currently it appears impossible to use CvEM to do classification eg. foreground/background segmentation based on colours. The predict function returns an integer index indicating which of the cluster has the highest score, but not the actual probability of a sample belonging to the CvEM model. The following simple change makes this possible.
em.cpp at line 288 to get rid of the normalisation:
//CV_CALL( cvConvertScale( &expo, _probs, 1./cvSum( &expo ).valr0 )); CV_CALL( cvCopy(&expo, _probs) ); With the changes made, one can get the probability of a sample for classification as follows: sample.data.flr0 = (float)r; sample.data.flr1 = (float)g; sample.data.flr2 = (float)b; em_model_FG.predict(&sample, probFG); em_model_BG.predict(&sample, probBG); double scoreFG = 0; double scoreBG = 0; // For GMM we use addition, not multiplication for(unsigned int k=0; k < GMM_FG; k++) scoreFG += probFG->data.db[k]; for(unsigned int k=0; k < GMM_BG; k++) scoreBG += probBG->data.db[k]; if(scoreFG > scoreBG) return 1; else return 0;
Or alternatively, make predict() return the probability by default.
Associated revisions
Merge pull request #964 from jet47:cuda-5.5-support
History
Updated by Alexander Shishkov about 13 years ago
- Description changed from Currently it appears impossible to use [[CvEM]] to do classification eg. fore... to Currently it appears impossible to use CvEM to do classification eg. foregrou... More
Updated by Alexander Shishkov almost 13 years ago
- Tracker changed from Feature to Patch
- Target version deleted ()
Updated by Alexander Shishkov almost 13 years ago
- Assignee deleted (
Maria Dimashova)
Updated by Maria Dimashova almost 13 years ago
- Assignee set to Maria Dimashova
Updated by Alexander Shishkov almost 13 years ago
- Target version deleted ()
Updated by Nghia Ho almost 13 years ago
This issue has been addressed somewhat in OpenCV 2.3.1 with new functions added but as of writing still contains bugs which need to be resolved. See http://code.opencv.org/issues/1361
Updated by Kirill Kornyakov almost 13 years ago
- Description changed from Currently it appears impossible to use CvEM to do classification eg. foregrou... to Currently it appears impossible to use CvEM to do classification eg. foregrou... More
Updated by Maria Dimashova almost 13 years ago
Thanks for the report. You can use CvEM::getLikelihood method for your purpose.
Note, we added new c++ implementation cv::EM and moved CvEM to the legacy module (cv::EM will be available in coming opencv2.4). So you should change include file from ml to legacy module. The implementation of CvEM methods was replaced by the call of cv::EM ones. CvEM writes the trained model in new format now, because previous version of write method had a bug (it saved all matrices twice).
cv::EM should solve many issues of the previous implementation. We added several new tests to check this. If you'll have some other problems from r8075, please open an issue.
- Status changed from Open to Cancelled
Updated by Andrey Kamaev almost 13 years ago
- Target version set to 2.4.0