使用Gabor滤波器处理图像时异常的问题排查求助
Gabor滤波器应用异常问题排查
我尝试复现某篇已发表的目标识别论文中的Gabor函数及参数,给图像应用Gabor滤波器,但输出结果不符合预期——仅在图像左上角出现部分白/灰色圆形Gabor渐变,其余区域均为黑色像素。我排查了很久没找到问题,求帮忙。
最初的循环代码是这样的:
output = gabor_output if output > 0: output = output else: output = 0
这段代码直接导致输出全黑,所以我改成了现在的代码来排查问题。但我希望最终能保留上面output = output的逻辑,而不是现在用的output = 1。
下面是我当前使用的完整代码:
# Gabor Function from S1 of "Robust Object Recognition" paper import numpy as np import matplotlib.pyplot as plt from PIL import Image import math orientation_1 = 0.0 orientation_2 = 45.0 orientation_3 = 90.0 orientation_4 = 135.0 def compute_x0(x, y, orientation): x0 = (x * math.cos(orientation)) + (y * math.sin(orientation)) return x0 def compute_y0(x, y, orientation): y0 = (-x * math.sin(orientation)) + (y * math.cos(orientation)) return y0 def gabor_function(x, y, orientation, wavelength, width, aspect_ratio=0.3): x0 = compute_x0(x, y, orientation) y0 = compute_y0(x, y, orientation) term_1 = np.exp(-(x0**2 + aspect_ratio**2 * y0**2) / (2 * width**2)) term_2 = math.cos(((2 * np.pi) / wavelength) * x0) output = term_1 * term_2 return output # Trying it out # Upload Image, convert to grayscale, convert to np.array image = Image.open('/Users/damondtrowbridge/Desktop/MATLAB/Face.png') bw = image.convert('L') bw_array = np.array(bw) / 255.0 # Crop to fit different images and adjust for pooling og_size = np.shape(bw_array) Xdim = (og_size[0]//4)*4 Ydim = (og_size[1]//4)*4 cropped = bw_array[0:Xdim, 0:Ydim] # Set up output array out_1 = np.zeros((Xdim-3, Ydim-3)) for x in range(3, Xdim - 3): for y in range(3, Ydim - 3): gabor_output = gabor_function(x, y, orientation_1, 3.5, 2.8, aspect_ratio=0.3) output = gabor_output * cropped[x, y] if output > 0: output = 1 else: output = 0 out_1[x, y] = output plt.imshow(out_1[:, :], cmap='gray', aspect='auto', vmin=0, vmax=1) plt.suptitle('Filtered Image') plt.show()
内容的提问来源于stack exchange,提问作者Sydney Trowbridge
相关产品推荐
相关产品推荐

