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
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.