from scipy import special
import numpy as np
def circularLowpassKernel(omega_c, N): # omega = cutoff frequency in radians (pi is max), N = horizontal size of the kernel, also its vertical size, must be odd.
kernel = np.fromfunction(lambda x, y: omega_c*special.j1(omega_c*np.sqrt((x - (N - 1)/2)**2 + (y - (N - 1)/2)**2))/(2*np.pi*np.sqrt((x - (N - 1)/2)**2 + (y - (N - 1)/2)**2)), [N, N])
if N % 2:
kernel[(N - 1)//2, (N - 1)//2] = omega_c**2/(4*np.pi)
return kernel
import matplotlib.pyplot as plt
kernelN = 11 # Horizontal size of the kernel, also its vertical size. Must be odd.
omega_c = np.pi # Cutoff frequency in radians <= pi
kernel = circularLowpassKernel(omega_c, kernelN)
plt.imshow(kernel, vmin=-1, vmax=1, cmap='bwr')
plt.colorbar()
plt.show()
kernelN = 41 # Horizontal size of the kernel, also its vertical size. Must be odd.
omega_c = np.pi/4 # Cutoff frequency in radians <= pi
kernel = circularLowpassKernel(omega_c, kernelN)
plt.imshow(kernel, vmin=-np.max(kernel), vmax=np.max(kernel), cmap='bwr')
plt.colorbar()
plt.show()