|
|
|
@ -47,7 +47,7 @@ ret,thresh5 = cv.threshold(img,127,255,cv.THRESH_TOZERO_INV) |
|
|
|
|
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV'] |
|
|
|
|
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5] |
|
|
|
|
|
|
|
|
|
for i in xrange(6): |
|
|
|
|
for i in range(6): |
|
|
|
|
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray',vmin=0,vmax=255) |
|
|
|
|
plt.title(titles[i]) |
|
|
|
|
plt.xticks([]),plt.yticks([]) |
|
|
|
@ -98,7 +98,7 @@ titles = ['Original Image', 'Global Thresholding (v = 127)', |
|
|
|
|
'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding'] |
|
|
|
|
images = [img, th1, th2, th3] |
|
|
|
|
|
|
|
|
|
for i in xrange(4): |
|
|
|
|
for i in range(4): |
|
|
|
|
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') |
|
|
|
|
plt.title(titles[i]) |
|
|
|
|
plt.xticks([]),plt.yticks([]) |
|
|
|
@ -153,7 +153,7 @@ titles = ['Original Noisy Image','Histogram','Global Thresholding (v=127)', |
|
|
|
|
'Original Noisy Image','Histogram',"Otsu's Thresholding", |
|
|
|
|
'Gaussian filtered Image','Histogram',"Otsu's Thresholding"] |
|
|
|
|
|
|
|
|
|
for i in xrange(3): |
|
|
|
|
for i in range(3): |
|
|
|
|
plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray') |
|
|
|
|
plt.title(titles[i*3]), plt.xticks([]), plt.yticks([]) |
|
|
|
|
plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256) |
|
|
|
@ -196,7 +196,7 @@ bins = np.arange(256) |
|
|
|
|
fn_min = np.inf |
|
|
|
|
thresh = -1 |
|
|
|
|
|
|
|
|
|
for i in xrange(1,256): |
|
|
|
|
for i in range(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: |
|
|
|
|