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

后端 未结 2 1700
时光取名叫无心
时光取名叫无心 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: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

提交回复
热议问题