Skip to main content

How to restore an initial scence using deconvolution

Image Restoration - deblurring

In this notebook I will show how to filter a blurred image in order to restore the initial data. I will use a simulation of granular structure (from SOPHISM simulations) that is free from optical aberrations and noise.

In [290]:
import WF_psf_mtf
from WF_psf_mtf import *
In [291]:
p = '/home/fatima/Desktop/solar_orbiter_project/codes/targets/MTF/'
data = pyfits.getdata(p+'Masi_hrt.fits')
data = data[300:600,300:600]
In [3]:
plt.figure(figsize=(18,10))
plt.imshow(data,origin='lower')
plt.colorbar()
Out[3]:
<matplotlib.colorbar.Colorbar at 0x7f02677faf50>

OTF synthesis

We will synthesis a wavefront aberration consisting of defocus and astigmatism

In [293]:
D = 140 #diameter of the aperture
lam = 617.3*10**(-6) #wavelength of observation
pix = 0.5 #plate scale
f = 4125.3            #effective focal length      
size = data.shape[0] #size of detector in pixels
In [294]:
coefficients = np.zeros(8)
coefficients[0] = 0
coefficients[1] = 0
coefficients[2] =0
coefficients[3] = 0.5
coefficients[4] = 0.1
coefficients[5] = 0.4
coefficients[6] = 0
coefficients[7] = 0
In [295]:
rpupil = pupil_size(D,lam,pix,size)
sim_phase = center(coefficients,size,rpupil)
Mask = mask(rpupil, size)


pupil_com = complex_pupil(sim_phase,Mask)
psf = PSF(pupil_com)
otf = OTF(psf)
mtf = MTF(otf)
In [296]:
plt.imshow(sim_phase)
Out[296]:
<matplotlib.image.AxesImage at 0x7f02679bf7d0>

No noise

I will produce the aberrated data without adding any noise

In [297]:
fft_image = np.fft.fft2(data)
temp = fft_image*otf
defoc = np.fft.ifft2(temp).real
In [298]:
fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(121,aspect='equal')
ax2 = fig.add_subplot(122,aspect='equal')
im=ax.imshow(data)
im2=ax2.imshow(defoc)
fig.subplots_adjust(right=0.8)
ax.set_title('Original',fontsize=22)
ax2.set_title('Defocused',fontsize=22)
Out[298]:
<matplotlib.text.Text at 0x7f02678ca4d0>

To restore the initial scene we could use the inverse filtering, which is dividing the blurred scene with the synthesized OTF, then using the inverse Fourier Transform:

In [299]:
fft_blurred = fft2(defoc)
restored = fft_blurred/otf
restored = ifft2(restored).real
In [300]:
plt.figure(figsize=(18,10))
plt.imshow(restored,origin='lower')
plt.colorbar()
Out[300]:
<matplotlib.colorbar.Colorbar at 0x7f02535b2090>