forked from adenarayana/digital-image-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython#005 Image Blur and Sharpen.py
59 lines (45 loc) · 1.47 KB
/
Python#005 Image Blur and Sharpen.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
import cv2
import numpy as np
import matplotlib.pyplot as plt
# original image
original_image = cv2.imread('image.png', 0)
# blur and sharpen convolution kernel
M = 3
blur_kernel = np.ones((M,M)) * 1/(M*M)
sharpen_kernel = np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]],
dtype=np.float32)
# apply the covolution
blur_image = cv2.filter2D(src=original_image,
ddepth=-1,
kernel=blur_kernel)
sharpen_image = cv2.filter2D(src=original_image,
ddepth=-1,
kernel=sharpen_kernel)
# display the result
plt.imshow(original_image, cmap='gray')
plt.axis('off')
plt.show()
plt.imshow(blur_image, cmap='gray')
plt.axis('off')
plt.show()
plt.imshow(sharpen_image, cmap='gray')
plt.axis('off')
plt.show()
# built in image bluring
builtin_blur = cv2.blur(src=original_image, ksize=(3,3))
plt.imshow(builtin_blur, cmap='gray')
plt.axis('off')
plt.show()
builtin_median = cv2.medianBlur(src=original_image, ksize=3)
plt.imshow(builtin_median, cmap='gray')
plt.axis('off')
plt.show()
builtin_gaussian = cv2.GaussianBlur(src=original_image,
ksize=(3,3),
sigmaX=0,
sigmaY=0)
plt.imshow(builtin_gaussian, cmap='gray')
plt.axis('off')
plt.show()