Python log-Gabor滤波器组的实现
我在读这篇文章,它将2D log gabor滤波器定义为: 文章还指出,滤波器仅覆盖频率空间的一侧,并显示在该图像中 在我尝试实现过滤器时,我得到的结果与论文中所说的不匹配。让我从我的实现开始,然后我将陈述问题 实施:Python log-Gabor滤波器组的实现,python,image-processing,computer-vision,Python,Image Processing,Computer Vision,我在读这篇文章,它将2D log gabor滤波器定义为: 文章还指出,滤波器仅覆盖频率空间的一侧,并显示在该图像中 在我尝试实现过滤器时,我得到的结果与论文中所说的不匹配。让我从我的实现开始,然后我将陈述问题 实施: 我创建了一个包含过滤器的2d数组,并对每个索引进行了变换,使频域的原点位于数组的中心,正x轴向右,正y轴向上 number_刻度=5#刻度分辨率 方向数=9#方向分辨率 N=康斯坦迪姆#图像尺寸 def getLogGaborKernal(比例、角度、logfun=math
number_刻度=5#刻度分辨率
方向数=9#方向分辨率
N=康斯坦迪姆#图像尺寸
def getLogGaborKernal(比例、角度、logfun=math.log2、norm=True):
#设置过滤器配置
中心刻度=对数(N)-刻度
中心角度=((np.pi/数量方向)*角度)如果(比例%2)\
其他((np.pi/数量方向)*(角度+0.5))
比例单位带宽=0.996*数学平方比(2/3)
角度\带宽=0.996*(1/数学sqrt(2))*(np.pi/数字\方向)
#将容纳过滤器的二维阵列
内核=np.0((N,N))
#获取二维阵列的中心,以便移动原点
中间=数学单元((N/2)+0.1)-1
#计算过滤器
对于范围内的x(0,康斯坦丁):
对于范围内的y(0,康斯坦丁):
#得到原点位于中心的变换x和y
#正x轴向右,正y轴向上
x_t,y_t=(x-中间),-(y-中间)
#计算给定索引处的过滤器值
核[y,x]=logGaborValue(x_t,y_t,中心刻度,中心角度,
比例(带宽、角度(带宽、logfun)
#使滤波器能量正常化
如果标准:
内核=内核/np.sum(内核**2)
返回内核
def logGaborValue(x,y,中心刻度,中心角度,刻度带宽,
角度(U带宽,logfun):
#转换为极坐标
原始,θ=getPolar(x,y)
#如果我们在中心,则在日志空间中返回0
#没有定义零
如果原始==0:
返回0
#转到对数极坐标
raw=logfun(原始)
#计算(θ-中心θ),我们计算cos(θ-中心θ)
#和sin(θ-中心θ),然后使用atan获得所需的值,
#这样我们就可以消除角距离环绕问题
costheta,sintheta=math.cos(θ),math.sin(θ)
ds=sintheta*math.cos(中心角)-costheta*math.sin(中心角)
dc=costheta*math.cos(中心角)+sintheta*math.sin(中心角)
dtheta=数学atan2(ds,dc)
#最终值,将径向分量乘以角度分量
返回math.exp(-0.5*((原始中心刻度)/刻度带宽)**2)*\
数学表达式(-0.5*(dtheta/angle_带宽)**2)
经过大量的代码分析,我发现我的实现是正确的,但是
getPolar
函数出错了,所以上面的代码应该可以正常工作。这是一个新代码,如果有人在寻找它,则不使用getPolar
函数:
number_scales = 5 # scale resolution
number_orientations = 8 # orientation resolution
N = 128 # image dimensions
def getFilter(f_0, theta_0):
# filter configuration
scale_bandwidth = 0.996 * math.sqrt(2/3)
angle_bandwidth = 0.996 * (1/math.sqrt(2)) * (np.pi/number_orientations)
# x,y grid
extent = np.arange(-N/2, N/2 + N%2)
x, y = np.meshgrid(extent,extent)
mid = int(N/2)
## orientation component ##
theta = np.arctan2(y,x)
center_angle = ((np.pi/number_orientations) * theta_0) if (f_0 % 2) \
else ((np.pi/number_orientations) * (theta_0+0.5))
# calculate (theta-center_theta), we calculate cos(theta-center_theta)
# and sin(theta-center_theta) then use atan to get the required value,
# this way we can eliminate the angular distance wrap around problem
costheta = np.cos(theta)
sintheta = np.sin(theta)
ds = sintheta * math.cos(center_angle) - costheta * math.sin(center_angle)
dc = costheta * math.cos(center_angle) + sintheta * math.sin(center_angle)
dtheta = np.arctan2(ds,dc)
orientation_component = np.exp(-0.5 * (dtheta/angle_bandwidth)**2)
## frequency componenet ##
# go to polar space
raw = np.sqrt(x**2+y**2)
# set origin to 1 as in the log space zero is not defined
raw[mid,mid] = 1
# go to log space
raw = np.log2(raw)
center_scale = math.log2(N) - f_0
draw = raw-center_scale
frequency_component = np.exp(-0.5 * (draw/ scale_bandwidth)**2)
# reset origin to zero (not needed as it is already 0?)
frequency_component[mid,mid] = 0
return frequency_component * orientation_component
谢谢你回答你自己的问题。我也在寻找关于log gabor滤镜用于虹膜识别的信息,发现你的帖子非常有用