-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradients.py
36 lines (24 loc) · 875 Bytes
/
gradients.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
import cv2 as cv
import numpy as np
img = cv.imread('Resources/Photos/cats.jpg')
cv.imshow('Cats', img)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)
#Laplacian , a way to detect edges on the image
lap = cv.Laplacian(gray, cv.CV_64F)
#params --> (image, data depth)
lap = np.uint8(np.absolute(lap))
cv.imshow('Laplacian', lap)
#Sobel - gradient magnitude representation
sobelx = cv.Sobel(gray, cv.CV_64F, 1, 0)
sobely = cv.Sobel(gray, cv.CV_64F, 0, 1)
#params --> (image, data depth, x_direction, y_direction)
cv.imshow('Sobel x', sobelx)
cv.imshow('Sobel y', sobely)
combined_sobel = cv.bitwise_or(sobelx, sobely)
cv.imshow('Combined Sobel', combined_sobel)
#Canny
canny = cv.Canny(gray, 150, 175)
#canny is an advanced kind of edge detection algo that uses sobel and laplacian at it's various stages.
cv.imshow('Canny', canny)
cv.waitKey(0)