def make2d(w1d, x=None):
"""
Create 2D filter from the 1D one.
Parameters
----------
w1d : 1D `~numpy.ndarray`
The input 1D filter/window
x : 1D `~numpy.ndarray`, optional
The X-axis values of the input ``w1d`` filter
Returns
-------
w2d : 2D `~numpy.ndarray`
Created 2D filter/window from the input 1D one.
Credit
------
[1] MATLAB - creating 2D convolution filters
https://cn.mathworks.com/matlabcentral/newsreader/view_thread/23588
"""
if x is None:
L = len(w1d)
M = (L-1) / 2
x = np.linspace(-M, M, num=L)
xmax = np.max(x)
xsize = int(2 * xmax + 1)
xx = np.linspace(-xmax, xmax, num=xsize)
xg, yg = np.meshgrid(xx, xx)
r = np.sqrt(xg**2 + yg**2)
ridx = (r <= xmax)
w2d = np.zeros(shape=(xsize, xsize))
finterp = interpolate.interp1d(x=x, y=w1d, kind="linear")
w2d[ridx] = finterp(r[ridx])
return w2d
评论列表
文章目录