log-gabor滤波器python代码
时间: 2023-04-03 11:04:05 浏览: 268
以下是 log-gabor 滤波器的 Python 代码:
```python
import numpy as np
import cv2
def log_gabor_filter(image, sigma, theta, Lambda, psi, gamma):
# 计算图像的傅里叶变换
fft_image = np.fft.fft2(image)
fft_shift_image = np.fft.fftshift(fft_image)
# 构造 log-gabor 滤波器
rows, cols = image.shape
u, v = np.meshgrid(np.arange(-cols/2, cols/2), np.arange(-rows/2, rows/2))
radius = np.sqrt(u**2 + v**2)
radius[0, 0] = 1
theta = theta * np.pi / 180
wavelength = Lambda
fo = 1.0 / wavelength
sigma_f = fo / np.pi * np.sqrt(np.log(2) / 2) * (np.power(2, gamma) + 1) / (np.power(2, gamma) - 1)
sigma_x = sigma / fo
sigma_y = sigma / fo / gamma
x_theta = u * np.cos(theta) + v * np.sin(theta)
y_theta = -u * np.sin(theta) + v * np.cos(theta)
gb = np.exp(-0.5 * (np.power(x_theta, 2) / np.power(sigma_x, 2) + np.power(y_theta, 2) / np.power(sigma_y, 2))) * np.cos(2 * np.pi * fo * x_theta + psi)
gb = gb * (radius <= radius.max() / 2)
# 对图像进行滤波
filtered_image = np.fft.ifft2(np.fft.ifftshift(fft_shift_image * gb))
return np.abs(filtered_image)
# 测试代码
if __name__ == '__main__':
image = cv2.imread('lena.jpg', cv2.IMREAD_GRAYSCALE)
filtered_image = log_gabor_filter(image, 10, 0, 10, 0, 0.5)
cv2.imshow('filtered image', filtered_image.astype(np.uint8))
cv2.waitKey(0)
cv2.destroyAllWindows()
```
希望能对你有所帮助!
阅读全文