-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThresholding
More file actions
31 lines (25 loc) · 884 Bytes
/
Thresholding
File metadata and controls
31 lines (25 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
import matplotlib.pyplot as plt
def main():
path = "D:\\image_processing_files\\Dataset\\"
imgpath1 = path + "gray21.512.tiff"
img = cv2.imread(imgpath1, 1)
th = 127
max_value = 255
ret,o1 = cv2.threshold(img,th,max_value,cv2.THRESH_BINARY)
ret,o2 = cv2.threshold(img,th,max_value,cv2.THRESH_BINARY_INV)
ret,o3 = cv2.threshold(img,th,max_value,cv2.THRESH_TOZERO)
ret,o4 = cv2.threshold(img,th,max_value,cv2.THRESH_TOZERO_INV)
ret,o5 = cv2.threshold(img,th,max_value,cv2.THRESH_TRUNC)
output = [img,o1,o2,o3,o4,o5]
titles = ['Original_image','Bin','Bin_inv',
'Zero','Zero_inv','Trunc']
for i in range(6):
plt.subplot(2,3,i+1)
plt.imshow(output[i])
plt.title(titles[i])
plt.xticks([])
plt.yticks([])
plt.show()
if __name__ == "__main__":
main()