-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdaptive.py
84 lines (67 loc) · 2.04 KB
/
Adaptive.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import mahotas as mahotas
__author__ = 'altug'
import numpy as np
import argparse
import cv2
import glob
class Adaptive:
def __init__(self):
print ''
def getThresh(self, imagePath):
self.imagePath = imagePath
image = cv2.imread(self.imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(image, (5, 5), 0)
#cv2.imshow("Gray", image)
#cv2.imshow("Blurred", blurred)
thresh = cv2.adaptiveThreshold(blurred, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 15, 3)
cv2.imshow("Gaussian Thresh", thresh)
#cv2.waitKey(0)
return thresh
'''
imagePaths = sorted(glob.glob("dataset/papatya" + "/*.jpg"))
i = 1
for imagePath in imagePaths:
image = cv2.imread(imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(image, (5, 5), 0)
#cv2.imshow("Gray", image)
#cv2.imshow("Blurred", blurred)
thresh = cv2.adaptiveThreshold(blurred, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 15, 3)
#cv2.imshow("Gaussian Thresh", thresh)
cv2.imwrite('dataset/imagesjpg/thtrain_papatya_'+str(i)+'.jpg', thresh)
i=i+1
'''
'''
thresh = cv2.adaptiveThreshold(blurred, 255,
cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 11, 4)
cv2.imshow("Mean Thresh", thresh)
'''
'''
TERS TRESH
(T, thresh) = cv2.threshold(blurred, 155, 255, cv2.THRESH_BINARY)
(T, threshInv) = cv2.threshold(blurred, 155, 255, cv2.
THRESH_BINARY_INV)
cv2.imshow("Ters", threshInv)
cv2.imshow("Son Hali", cv2.bitwise_and(image, image, mask =
threshInv))
'''
'''
OTSU VE RIDDLE
T = mahotas.thresholding.otsu(image)
print "Otsu degeri: %d" % (T)
thresh = image.copy()
thresh[thresh > T] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
cv2.imshow("Otsu", thresh)
T = mahotas.thresholding.rc(blurred)
print "Riddler-Calvard: %d" % (T)
thresh = image.copy()
thresh[thresh > T] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
cv2.imshow("Riddler-Calvard", thresh)
'''