-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image_Edging.py
51 lines (38 loc) · 1.38 KB
/
Image_Edging.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
import cv2
from skimage import img_as_ubyte, img_as_int
from scipy import ndimage
import numpy as np
from matplotlib import pyplot as plt
def prewitt_edge(image_name):
img_file = cv2.imread(image_name, 0)
img = img_as_int(img_file)
prewitt_vertical = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]], dtype="float64")
prewitt_vertical_out = img_as_ubyte(ndimage.convolve(img, prewitt_vertical, mode='constant', cval=0.0))
plt.imshow(prewitt_vertical_out)
plt.title("Prewitt Edge Detection")
plt.show()
def sobel_edge(image_name):
img_file = cv2.imread(image_name, 0)
sobel_x = cv2.Sobel(img_file, -1, 1, 0, ksize=5)
sobel_y = cv2.Sobel(img_file, -1, 0, 1, ksize=5)
plt.imshow(sobel_x, cmap = 'gray')
plt.title("Sobel-X Edge Detection")
plt.show()
plt.imshow(sobel_y, cmap = 'gray')
plt.title("Sobel-Y Edge Detection")
plt.show()
def laplassian_edge(image_name):
img_file = cv2.imread(image_name)
output = cv2.Laplacian(img_file, -1)
plt.imshow(output)
plt.title("Laplassian Edge")
plt.show()
if __name__ == "__main__":
image_name = input("Enter the image name: ")
mode = int(input("Select the mode (1 - Prewitt, 2 - Sobel, 3 - Laplassian): "))
if mode == 1:
prewitt_edge(image_name)
elif mode == 2:
sobel_edge(image_name)
elif mode == 3:
laplassian_edge(image_name)