forked from kokonior/Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeteksi_tepi.py
More file actions
35 lines (27 loc) · 785 Bytes
/
Deteksi_tepi.py
File metadata and controls
35 lines (27 loc) · 785 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
from scipy import ndimage
import cv2
import numpy as np
def sobel (img):
im = img.astype('int32')
gx = ndimage.sobel(im, 1)
gy = ndimage.sobel(im, 0)
magnitude = np.hypot(gx, gy)
magnitude = magnitude*255 / np.max(magnitude)
cv2.imwrite('sobel.png', magnitude)
def prewitt(img):
im = img.astype('int32')
gx = ndimage.prewitt(im, 1)
gy = ndimage.prewitt(im, 0)
magnitude = np.hypot(gx, gy)
magnitude = magnitude * 255 / np.max(magnitude)
cv2.imwrite('prewitt.png', magnitude)
def canny(img, th1, th2):
can = cv2.Canny(img, th1, th2)
cv2.imwrite('canny.png', can)
image = cv2.imread('File/Monalisa.PNG', 0)
sobel(image)
prewitt(image)
canny(image, 90, 200)
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()