xoa.filter.generate_orthogonal_kernel

xoa.filter.generate_orthogonal_kernel(kernels, window_func='ones', fill_value=0.0)[source]

Generate an nD kernel from orthogonal 1d kernels

Parameters:
  • kernels (list) – List of scalars and/or 1d kernels. In case of a scalar, it is converted to an 1d kernel with the window_func parameter.

  • window_func (str, callable) – Function that take a size parameter as unique argument. If a string, it is expected to be a numpy window function.

  • fill_value (float) – Value to set when outside window bounds, when creating an 1d kernel from a floating size

Returns:

np.ndarray – Orthogonal kernel array

Example

# From sizes and functions
In [1]: ny, nx = (21, 31)

In [2]: kernel = generate_orthogonal_kernel((ny, nx), "bartlett")

In [3]: j, i = 5, 20

In [4]: plt.plot([3, 4])
Out[4]: [<matplotlib.lines.Line2D at 0x7f37c1d35150>]

In [5]: fig = plt.figure(constrained_layout=True)

In [6]: gs = GridSpec(3, 3, figure=fig)

In [7]: ax0 = fig.add_subplot(gs[1:, :2])

In [8]: ax0.matshow(kernel)
Out[8]: <matplotlib.image.AxesImage at 0x7f37c1629110>

In [9]: ax0.axhline(j, color='tab:red')
Out[9]: <matplotlib.lines.Line2D at 0x7f37c15af8d0>

In [10]: ax1 = fig.add_subplot(gs[0, :2], sharex=ax0)

In [11]: ax1.plot(np.arange(nx), kernel[j], color='tab:red')
Out[11]: [<matplotlib.lines.Line2D at 0x7f37c14989d0>]

In [12]: ax2 = fig.add_subplot(gs[1:, -1], sharey=ax0)

In [13]: ax2.plot(kernel[:, i], np.arange(ny), color='tab:orange');

In [14]: ax0.axvline(i, color='tab:orange')
Out[14]: <matplotlib.lines.Line2D at 0x7f37c149bb50>

# From 1d kernels
In [15]: kernel = generate_orthogonal_kernel(([1, 1, 1], [1, 2, 3, 2, 1]))

In [16]: plt.figure()
Out[16]: <Figure size 640x480 with 0 Axes>

In [17]: plt.matshow(kernel);
../_images/api.filter.generate_orthogonal_kernel_0.png ../_images/api.filter.generate_orthogonal_kernel_1.png