-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge_detection.py
88 lines (65 loc) · 2.24 KB
/
edge_detection.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import cv2
from matplotlib import pyplot as plt
import numpy as np
from Homeworks.convolution import convolution
images = []
def robert_cross(image, gx, gy):
imgrc_x = convolution(image, gx)
plt.imshow(imgrc_x, cmap="gray")
plt.title("Robert Cross // Horizontal Filter Gx")
plt.show()
images.append(imgrc_x)
imgrc_y = convolution(image, gy)
plt.imshow(imgrc_y, cmap="gray")
plt.title("Robert Cross // Vertical Filter Gy")
plt.show()
images.append(imgrc_y)
def prewitt(image, gx, gy):
imgp_x = convolution(image, gx)
plt.imshow(imgp_x, cmap="gray")
plt.title("Prewitt // Horizontal Filter Gx")
plt.show()
images.append(imgp_x)
imgp_y = convolution(image, gy)
plt.imshow(imgp_y, cmap="gray")
plt.title("Prewitt // Vertical Filter Gy")
plt.show()
images.append(imgp_y)
def sobel(image, gx, gy):
img_x = convolution(image, gx)
plt.imshow(img_x, cmap="gray")
plt.title("Sobel // Horizontal Filter Gx")
plt.show()
images.append(img_x)
img_y = convolution(image, gy)
plt.imshow(img_y, cmap="gray")
plt.title("Sobel // Vertical Filter Gy")
plt.show()
images.append(img_y)
h_sobel_filter = np.array([[-1, 0, 1],
[-2, 0, 2],
[-1, 0, 1]])
v_sobel_filter = np.array([[1, 2, 1],
[0, 0, 0],
[-1, -2, -1]])
h_prewitt_filter = np.array([[-1, 0, 1],
[-1, 0, 1],
[-1, 0, 1]])
v_prewitt_filter = np.array([[1, 1, 1],
[0, 0, 0],
[-1, -1, -1]])
h_rcross_filter = np.array([[1, 0],
[0, -1]])
v_rcross_filter = np.array([[0, 1],
[-1, 0]])
image = cv2.imread('images\\resim.jpg', 0)
sobel(image, h_sobel_filter, v_sobel_filter)
prewitt(image, h_prewitt_filter, v_prewitt_filter)
robert_cross(image, h_rcross_filter, v_rcross_filter)
row1 = np.hstack((images[0], images[1]))
row2 = np.hstack((images[0], images[1]))
row3 = np.hstack((images[0], images[1]))
table = np.vstack((row1, row2, row3))
plt.imshow(table, cmap="gray")
plt.title("Robert Cross, Prewitt, Sobel // Comparison")
plt.show()