How to Calculate the Gradient Magnitude and Angle?
import cv2
import numpy as np
def calculate(image):
image = np.sqrt(image)
gx = cv2.Sobel(np.float32(image), cv2.CV_32F, 1, 0)
gy = cv2.Sobel(np.float32(image), cv2.CV_32F, 0, 1)
mag, ang = cv2.cartToPolar(gx, gy)
return mag, ang, gx, gy
img=cv2.imread("bird.jpeg")
m,a,gx,gy=calculate(img)
cv2.imshow("gx",gx)
cv2.imshow("gy",gy)
print(m)
print(a)
cv2.waitKey()
Input:
Comments
Post a Comment