From 17fe63446fdd0c45a605467db2a444ee4a7d6ed4 Mon Sep 17 00:00:00 2001 From: ankit6979 Date: Tue, 4 Feb 2020 17:52:18 +0530 Subject: [PATCH] Merge pull request #16499 from ankit6979:3.4 * Update py_thresholding.markdown * :memo: Update py_thresholding.markdown --- .../py_imgproc/py_thresholding/py_thresholding.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown b/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown index d192288721..285124d17c 100644 --- a/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown +++ b/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown @@ -188,7 +188,7 @@ blur = cv.GaussianBlur(img,(5,5),0) # find normalized_histogram, and its cumulative distribution function hist = cv.calcHist([blur],[0],None,[256],[0,256]) -hist_norm = hist.ravel()/hist.max() +hist_norm = hist.ravel()/hist.sum() Q = hist_norm.cumsum() bins = np.arange(256) @@ -199,6 +199,8 @@ thresh = -1 for i in xrange(1,256): p1,p2 = np.hsplit(hist_norm,[i]) # probabilities q1,q2 = Q[i],Q[255]-Q[i] # cum sum of classes + if q1 < 1.e-6 or q2 < 1.e-6: + continue b1,b2 = np.hsplit(bins,[i]) # weights # finding means and variances