Is there a equivalent of scipy.signal.deconvolve for 2D arrays?

后端 未结 2 1701
时光取名叫无心
时光取名叫无心 2021-02-03 11:16

I would like to deconvolve a 2D image with a point spread function (PSF). I\'ve seen there is a scipy.signal.deconvolve function that works for one-dimensional arra

相关标签:
2条回答
  • 2021-02-03 11:43

    Note that deconvolving by division in the fourier domain isn't really useful for anything but demonstration purposes; any kind of noise, even numerical, may render your outcome completely unusable. One may regularize the noise in various ways; but in my experience, an RL iteration is easier to implement, and in many ways more physically justifiable.

    0 讨论(0)
  • 2021-02-03 11:51

    These functions using fftn, ifftn, fftshift and ifftshift from the SciPy's fftpack package seem to work:

    from scipy import fftpack
    
    def convolve(star, psf):
        star_fft = fftpack.fftshift(fftpack.fftn(star))
        psf_fft = fftpack.fftshift(fftpack.fftn(psf))
        return fftpack.fftshift(fftpack.ifftn(fftpack.ifftshift(star_fft*psf_fft)))
    
    def deconvolve(star, psf):
        star_fft = fftpack.fftshift(fftpack.fftn(star))
        psf_fft = fftpack.fftshift(fftpack.fftn(psf))
        return fftpack.fftshift(fftpack.ifftn(fftpack.ifftshift(star_fft/psf_fft)))
    
    star_conv = convolve(star, psf)
    star_deconv = deconvolve(star_conv, psf)
    
    f, axes = plt.subplots(2,2)
    axes[0,0].imshow(star)
    axes[0,1].imshow(psf)
    axes[1,0].imshow(np.real(star_conv))
    axes[1,1].imshow(np.real(star_deconv))
    plt.show()
    

    The image in the left bottom shows the convolution of the two Gaussian functions in the upper row, and the reverse of the effects of convolution is shown in the bottom right.

    enter image description here

    0 讨论(0)
提交回复
热议问题