This week Features and Corners.
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 |
# 1. Open any image; # 2. Use Sobel to find the horizontal and vertical gradients; # 3. Create an edge mask using Canny (255 for edges 0 for not); # 4. On the edges, show the magnitude of the gradients. # Advanced Task: Devise a way to visualise the direction of the gradients on the edges. import numpy as np import cv2 from matplotlib import pyplot as plt from matplotlib import image as image import easygui I = cv2.imread("ball.jpg") G = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY) Ix = cv2.Sobel(G,ddepth=cv2.CV_64F,dx=1,dy=0) Iy = cv2.Sobel(G,ddepth=cv2.CV_64F,dx=0,dy=1) M = np.sqrt(Ix*Ix + Iy*Iy) # D = np.arctan(Iy/Ix) E = cv2.Canny(G,threshold1=100,threshold2=200) F = cv2.bitwise_and(Ix,Iy,mask=E) # plt.figure() # plt.subplot(2,3,2) # plt.imshow(Ix) # plt.subplot(2,3,1) # plt.imshow(Iy) # plt.subplot(2,3,3) # plt.imshow(E) # plt.show() # cv2.imshow("image", F) # key = cv2.waitKey(0) plt.subplot(231), plt.imshow(G, cmap ='gray') plt.subplot(232), plt.imshow(Ix, cmap ='gray') plt.subplot(233), plt.imshow(Iy, cmap ='gray') plt.subplot(234), plt.imshow(E, cmap ='gray') plt.subplot(235), plt.imshow(F, cmap ='gray') plt.subplot(236), plt.imshow(M, cmap ='gray') plt.show() |