Skip to content

Commit 14dc047

Browse files
committed
[add] add some lines
Add some lines to check the result of segmentation.
1 parent 536ef7b commit 14dc047

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

8ubS9.jpg

107 KB
Loading

canny_watershed.py

+32
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,34 @@ def canny_watershed(inputfile, outputfile, sigma, min_edge, ratio):
5757

5858
# Apply watershed algorithm
5959
cv.watershed(image, markers)
60+
6061

62+
'''
6163
mark = markers.astype('uint8')
6264
mark = cv.bitwise_not(mark)
6365
cv.imshow('marker v2', mark)
66+
'''
67+
68+
# Apply thresholding on the image to convert to binary image
69+
m = cv.convertScaleAbs(markers)
70+
ret, thresh = cv.threshold(m, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
71+
cv.imshow('thresh', thresh)
72+
73+
# Invert the thresh
74+
thresh_inv = cv.bitwise_not(thresh)
75+
cv.imshow('thresh_inv', thresh_inv)
76+
77+
# Bitwise and with the image mask thresh
78+
res = cv.bitwise_and(image, image, mask = thresh)
79+
cv.imshow('res', res)
80+
81+
# Bitwise and the image with mask as threshold invert
82+
res3 = cv.bitwise_and(image, image, mask = thresh_inv)
83+
cv.imshow('res3', res3)
84+
# Take the weighted average
85+
res4 = cv.addWeighted(res, 1, res3, 1, 0)
86+
cv.imshow('marker v2', res4)
87+
6488

6589
# Generate random color
6690
colors = []
@@ -90,14 +114,19 @@ def canny_watershed(inputfile, outputfile, sigma, min_edge, ratio):
90114
# Apply thresholding on the image to convert to binary image
91115
m = cv.convertScaleAbs(marker32)
92116
ret, thresh = cv.threshold(m, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
117+
cv.imshow('thresh', thresh)
93118
# Invert the thresh
94119
thresh_inv = cv.bitwise_not(thresh)
120+
cv.imshow('thresh_inv', thresh_inv)
95121
# Bitwise and with the image mask thresh
96122
res = cv.bitwise_and(image, image, mask = thresh)
123+
cv.imshow('res', res)
97124
# Bitwise and the image with mask as threshold invert
98125
res3 = cv.bitwise_and(image, image, mask = thresh_inv)
126+
cv.imshow('res3', res3)
99127
# Take the weighted average
100128
res4 = cv.addWeighted(res, 1, res3, 1, 0)
129+
cv.imshow('res4', res4)
101130
# Draw the contours on the image with green color and pixel width is 1
102131
final = cv.drawContours(res4, contours, -1, (0, 255, 0), 1)
103132
@@ -114,6 +143,8 @@ def canny_watershed(inputfile, outputfile, sigma, min_edge, ratio):
114143
print("Hello world")
115144
#canny_watershed(1, 1, 1, 1)
116145
#canny_watershed('四破魚(藍圓鰺)2.jpg', 0, 100, 3)
146+
#canny_watershed('8ubS9.jpg', 'output.jpg', 0, 100, 3)
147+
117148
with open('file_lists.txt', 'r') as f:
118149
for line in f:
119150
params = []
@@ -124,4 +155,5 @@ def canny_watershed(inputfile, outputfile, sigma, min_edge, ratio):
124155
canny_watershed(params[0], outputfile, float(params[1]), int(params[2]), int(params[3]))
125156
#filename = os.path.splitext(params[0])[0]
126157
#print(filename)
158+
127159
print("end")

0 commit comments

Comments
 (0)