Merge pull request #16499 from ankit6979:3.4
* Update py_thresholding.markdown
* 📝 Update py_thresholding.markdown
This commit is contained in:
parent
0673866ceb
commit
17fe63446f
@ -188,7 +188,7 @@ blur = cv.GaussianBlur(img,(5,5),0)
|
|||||||
|
|
||||||
# find normalized_histogram, and its cumulative distribution function
|
# find normalized_histogram, and its cumulative distribution function
|
||||||
hist = cv.calcHist([blur],[0],None,[256],[0,256])
|
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()
|
Q = hist_norm.cumsum()
|
||||||
|
|
||||||
bins = np.arange(256)
|
bins = np.arange(256)
|
||||||
@ -199,6 +199,8 @@ thresh = -1
|
|||||||
for i in xrange(1,256):
|
for i in xrange(1,256):
|
||||||
p1,p2 = np.hsplit(hist_norm,[i]) # probabilities
|
p1,p2 = np.hsplit(hist_norm,[i]) # probabilities
|
||||||
q1,q2 = Q[i],Q[255]-Q[i] # cum sum of classes
|
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
|
b1,b2 = np.hsplit(bins,[i]) # weights
|
||||||
|
|
||||||
# finding means and variances
|
# finding means and variances
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user