Skip to content

Commit 41e05e7

Browse files
committed
L17
1 parent 34f046c commit 41e05e7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

L17_gradients_edge_detection.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import cv2, numpy as np
2+
from matplotlib import pyplot as plt
3+
4+
#img = cv2.imread('./opencv/samples/data/messi5.jpg', cv2.IMREAD_GRAYSCALE)
5+
img = cv2.imread('./opencv/samples/data/sudoku.png', cv2.IMREAD_GRAYSCALE)
6+
7+
# Laplacian(img, dataType(64 bit float), kernel_size(ksize))
8+
lap = cv2.Laplacian(img, cv2.CV_64F, ksize = 3) # trova i contorni
9+
lap = np.uint8(np.absolute(lap)) # conversione a uint8
10+
11+
# Sobel(img, dataType, bool(dx), bool(dy), kernel_size)
12+
sobelX = cv2.Sobel(img, cv2.CV_64F, 1, 0)
13+
sobelY = cv2.Sobel(img, cv2.CV_64F, 0, 1)
14+
sobelX = np.uint8(np.absolute(sobelX))
15+
sobelY = np.uint8(np.absolute(sobelY))
16+
sobel_combined = cv2.bitwise_or(sobelX, sobelY)
17+
18+
19+
titles = ['image', 'Laplacian', 'SobelX', 'SobelY', 'SobelCombined']
20+
images = [img, lap, sobelX, sobelY, sobel_combined]
21+
22+
for i in range(len(images)):
23+
plt.subplot(2, 3, i+1), plt.imshow(images[i], 'gray')
24+
plt.title(titles[i])
25+
plt.xticks([]), plt.yticks([])
26+
27+
plt.show()

0 commit comments

Comments
 (0)