[Python] How to convolve a 3D array with Lorentzian kernel along axis=2?

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have an array img_data of shape (x, x, n_channels) and I want to convolve / smooth along the axis=2. Specifically, I would like the output shape to be (x,x,n_channels//3), after convolving the frequency channels. I want to use a Lorentzian as a kernel for convolving.

    I build the kernel as:

    def lorentzian_kernel(x, center, gamma):
    norm = 1 / np.pi
    kernel = norm * (gamma / ((x - center) ** 2 + gamma ** 2))
    return kernel


    So img_data is 3D array with n_channels depth and each channel is a square image. Each channel has a center frequency central_freq and FWHM which I shall use to make the kernels:

    gamma = FWHM / 2,

    center = central_freq and

    x = np.linspace(central_freq_channel1, central_freq_channeln, 1000)

    What operation should I use for smoothing along the channel axis? Do I have to do a dot product or convolution along axis=2 ? I am bit confused, so I would appreciate some comments. Thanks

    Continue reading...

Compartilhe esta Página