gpt4 book ai didi

python - 我怎样才能将这个 Gabor 补丁扩展到边界框的大小?

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:09 24 4
gpt4 key购买 nike

我正在尝试创建一个称为 Gabor patch 的二维图像可变大小。 Gabor 补丁最好被认为是二维正弦和二维高斯的卷积。

下面是用于生成代码的函数。代码移植自 this tutorial对于 Matlab(假设 import numpy as np):

def gabor_patch(size, lambda_, theta, sigma, phase, trim=.005):
"""Create a Gabor Patch

size : int
Image size (n x n)

lambda_ : int
Spatial frequency (px per cycle)

theta : int or float
Grating orientation in degrees

sigma : int or float
gaussian standard deviation (in pixels)

phase : float
0 to 1 inclusive
"""
# make linear ramp
X0 = (np.linspace(1, size, size) / size) - .5

# Set wavelength and phase
freq = size / float(lambda_)
phaseRad = phase * 2 * np.pi

# Make 2D grating
Xm, Ym = np.meshgrid(X0, X0)

# Change orientation by adding Xm and Ym together in different proportions
thetaRad = (theta / 360.) * 2 * np.pi
Xt = Xm * np.cos(thetaRad)
Yt = Ym * np.sin(thetaRad)
grating = np.sin(((Xt + Yt) * freq * 2 * np.pi) + phaseRad)

# 2D Gaussian distribution
gauss = np.exp(-((Xm ** 2) + (Ym ** 2)) / (2 * (sigma / float(size)) ** 2))

# Trim
gauss[gauss < trim] = 0

return grating * gauss

我希望 Gabor 补丁的大小与 size 参数成比例地增加。换句话说,我希望边界框的尺寸决定补丁的直径。问题是这个函数不以这种方式运行。相反,边界框的大小会增加,而补丁会保持相同的尺寸。

例一:size = 100

enter image description here

示例 2:大小 = 500

enter image description here

我完全看不出我做错了什么。有人可以指出我正确的方向吗?

如果我可以提供更多信息,请告诉我。谢谢!

最佳答案

好吧,原来我是傻了。

实现我想要的方法是将 sigma 参数设置为更大的值,因为这会扩大高斯分布的“传播”,从而暴露更多的正弦纹理。

tl;dr:解决方案是增加 sigma

启迪达成!

关于python - 我怎样才能将这个 Gabor 补丁扩展到边界框的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19039674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com