def gabor_2d(M, N, sigma, theta, xi, slant=1.0, offset=0, fft_shift=None):
gab = np.zeros((M, N), np.complex64)
R = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], np.float32)
R_inv = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]], np.float32)
D = np.array([[1, 0], [0, slant * slant]])
curv = np.dot(R, np.dot(D, R_inv)) / ( 2 * sigma * sigma)
for ex in [-2, -1, 0, 1, 2]:
for ey in [-2, -1, 0, 1, 2]:
[xx, yy] = np.mgrid[offset + ex * M:offset + M + ex * M, offset + ey * N:offset + N + ey * N]
arg = -(curv[0, 0] * np.multiply(xx, xx) + (curv[0, 1] + curv[1, 0]) * np.multiply(xx, yy) + curv[
1, 1] * np.multiply(yy, yy)) + 1.j * (xx * xi * np.cos(theta) + yy * xi * np.sin(theta))
gab = gab + np.exp(arg)
norm_factor = (2 * 3.1415 * sigma * sigma / slant)
gab = gab / norm_factor
if (fft_shift):
gab = np.fft.fftshift(gab, axes=(0, 1))
return gab
评论列表
文章目录