-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path#14_blurring.py
57 lines (46 loc) · 1.72 KB
/
#14_blurring.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
import cv2
import numpy as np
image = cv2.imread("images/bug_noisy.jpg")
#? Average Blurring #
def avg_blur():
#! The Kernel Side Length Must be Odd
blured = np.hstack([image,
cv2.blur(image, (3, 3)),
cv2.blur(image, (5, 5)),
cv2.blur(image, (7, 7)),
cv2.blur(image, (13, 13))])
cv2.imshow("Average Blur", blured)
cv2.waitKey(0)
#? Gaussian Blurring #
def gauss_blur():
# By setting the third parameter to 0, we are instructing OpenCV
# to automatically compute the weights based on our kernel size
g_blured = np.hstack([image,
cv2.GaussianBlur(image, (3, 3), 0),
cv2.GaussianBlur(image, (5, 5), 0),
cv2.GaussianBlur(image, (7, 7), 0),
cv2.GaussianBlur(image, (13, 13), 0)])
cv2.imshow("Gaussian Blur", g_blured)
cv2.waitKey(0)
#? Median Blurring #
def median_blur():
m_blured = np.hstack([image,
cv2.medianBlur(image, 3),
cv2.medianBlur(image, 5),
cv2.medianBlur(image, 7),
cv2.medianBlur(image, 13)])
cv2.imshow("Median Blur", m_blured)
cv2.waitKey(0)
#? Bilateral Blurring #
def bilateral():
filtered = np.hstack([image,
cv2.bilateralFilter(image, 5, 21, 21),
cv2.bilateralFilter(image, 7, 31, 31),
cv2.bilateralFilter(image, 9, 41, 41),
cv2.bilateralFilter(image, 12, 51, 51)])
cv2.imshow("Bilateral", filtered)
cv2.waitKey(0)
avg_blur()
gauss_blur()
median_blur()
bilateral()