-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfilterlib.py
More file actions
72 lines (64 loc) · 2.42 KB
/
filterlib.py
File metadata and controls
72 lines (64 loc) · 2.42 KB
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
import cv2
#=============================================================================================
# Call this function if selected filterName is not defined
#=============================================================================================
def filterNotDefined(inputImage,args=None):
print('Filter name not defined in filterlib.py')
return inputImage
#========================================
# Usage: grey()
# convert to grey image
#========================================
def grey(inputImage,args=None):
if len(inputImage.shape) == 3:
return cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
else:
return inputImage
#========================================
# Usage: color()
# convert to color image
#========================================
def color(inputImage,args=None):
if len(inputImage.shape) == 2:
return cv2.cvtColor(inputImage, cv2.COLOR_GRAY2BGR)
else:
return inputImage
#========================================
# Usage: blur(radius)
# Since only odd number is allowed in Gaussian blur,
# we use 2*n+1 as the radius
#========================================
def blur(inputImage,args):
arg = args.split(',')
return cv2.GaussianBlur(inputImage,(int(arg[0])*2+1,int(arg[0])*2+1),0)
#========================================
# threshold(lowerBound,higherBound)
# Input must be a greyscale image
#========================================
def threshold(inputImage,args):
arg = args.split(',')
_, ret = cv2.threshold(inputImage,int(arg[0]),int(arg[1]),cv2.THRESH_BINARY)
return ret
#========================================
# canny(minVal,maxVal)
# Input must be a greyscale image
#========================================
def canny(inputImage,args):
arg = args.split(',')
return cv2.Canny(inputImage,int(arg[0]),int(arg[1]))
#========================================
# erode(img, kernel, iterations=1)
# Input must be a binary image
#========================================
def erode(inputImage,args):
arg = args.split(',')
kernel = np.ones((int(arg[0]),int(arg[0])), np.uint8)
return cv2.erode(inputImage, kernel, iterations=1)
#========================================
# dilate(img, kernel, iterations=1)
# Input must be a binary image
#========================================
def dilate(inputImage,args):
arg = args.split(',')
kernel = np.ones((int(arg[0]),int(arg[0])), np.uint8)
return cv2.dilate(inputImage, kernel, iterations=1)