-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_image_gradient_and_canny_edge.py
More file actions
51 lines (42 loc) · 1.17 KB
/
Copy path17_image_gradient_and_canny_edge.py
File metadata and controls
51 lines (42 loc) · 1.17 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
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('images/messi5.jpg', cv.IMREAD_GRAYSCALE)
lap = cv.Laplacian(img, cv.CV_64F, ksize=3)
# Changing the value in uinsigned
# int8 which is for output using numpy
lap = np.uint8(np.absolute(lap))
# Sobel X and Y method
# Here the first 1 is dx which is order of derivative X (Direction X)
# And the 0 is dy which is order of derivative Y (Direction Y)
sobelX = cv.Sobel(img, cv.CV_64F, 1, 0)
sobelY = cv.Sobel(img, cv.CV_64F, 0, 1)
# Changing the value in uinsigned
# int8 which is for output using numpy
sobelX = np.uint8(np.absolute(sobelX))
sobelY = np.uint8(np.absolute(sobelY))
# Sobel XY combined method
sobelCombined = cv.bitwise_or(sobelX, sobelY)
# Canny edge method
edges = cv.Canny(img, 100, 200)
titles = [
'Image',
'Laplacian',
'SobelX',
'SobelY',
'sobelCombined',
'CannyEgde'
]
images = [
img,
lap,
sobelX,
sobelY,
sobelCombined,
edges
]
for i in range(6):
plt.subplot(2, 3, i+1), plt.imshow(images[i], 'gray')
plt.title(titles[i])
plt.xticks([]), plt.yticks([])
plt.show()