我想从图像到x和y方向获得渐变。但是我的函数是高斯函数,但我没有实现图像的渐变。你能建议梯度的方法吗?
这是我的高斯极限。
X_test = np.arange(-10, 10, 1)
这是我的高斯公式(衍生的高斯形式)
sigma = 5
x_direction = ((-2*X_test)*np.exp(-(np.square(X_test/2)/sigma)))/sigma
总代码:
import cv2
import numpy as np
import math
np.set_printoptions(threshold=5)
img = cv2.imread("...\\test_2.jpg",0)
X_test = np.arange(-10, 10, 1)
sigma = 5
x_direction = ((-2*X_test)*np.exp(-(np.square(X_test/2)/sigma)))/sigma
dst1 = cv2.filter2D(img,cv2.CV_8U,x_direction)
cv2.imshow('gausssian_x',dst1)
Y_test = np.arange(-10, 10, 1)
y_direction = ((-2*Y_test)*np.exp(-(np.square(Y_test/2)/sigma)))/sigma
dst2 = cv2.filter2D(img,-1,y_direction)
cv2.imshow('gausssian_y',dst2)
cv2.waitKey(0)
cv2.destroyAllWindows()