forked from samwestby/OpenCV-Python-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_filtering.py
50 lines (42 loc) · 1.05 KB
/
7_filtering.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
import cv2
import numpy as np
img = cv2.imread("assets/cat.jpg")
# filter2D
blur_filter = np.array([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
])
blur_filter = blur_filter / 9
blur_img = cv2.filter2D(img, ddepth=-1,
kernel=blur_filter)
# NO FILTER // BRIGHTNESS
no_filter = np.array([
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
])
no_filter = no_filter * 2
bright_img = cv2.filter2D(img, ddepth=-1,
kernel=no_filter)
# BLUR
blur_img = cv2.blur(img, ksize=(111, 111))
# GAUSSIAN BLUR
gaus_img = cv2.GaussianBlur(img, ksize=(11, 11),
sigmaX=30, sigmaY=300)
# SHARPEN
sharpen_filter = np.array([
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]
])
sharp_img = cv2.filter2D(img, ddepth=-1,
kernel=sharpen_filter)
# EDGE DETECTION // LAPLACIAN
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_img = cv2.GaussianBlur(img, ksize=(3, 3),
sigmaX=1, sigmaY=1)
edges = cv2.Laplacian(gray_img, ddepth=-1)
cv2.imshow("Cat!", edges)
cv2.waitKey(0)
cv2.destroyAllWindows()