-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj.py
More file actions
35 lines (25 loc) · 795 Bytes
/
j.py
File metadata and controls
35 lines (25 loc) · 795 Bytes
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
import scipy.signal
import numpy as np
import matplotlib.pyplot as plt
def rgb2gray(rgb):
'''
convert rgb image to gray scale, it uses formula
gray_img = 0.299 R + 0.587 G + 0.114 B
'''
return np.dot(rgb[..., :3], [0.299, 0.587, 0.114])
# read image
im = plt.imread("img/photo.png").astype(float)
gray = rgb2gray(im)
gray /= 255
plt.imshow(gray, interpolation='none', cmap=plt.cm.gray)
# emmboss filter
kernel = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
em_img = scipy.signal.convolve2d(gray, kernel)
em_img *= 255
plt.subplot(1, 3, 1)
plt.imshow(im, interpolation='none', cmap=plt.cm.gray)
plt.subplot(1, 3, 2)
plt.imshow(gray, interpolation='none', cmap=plt.cm.gray)
plt.subplot(1, 3, 3)
plt.imshow(em_img, interpolation='none', cmap=plt.cm.gray)
plt.show()