I'm working on blind deconvoltuion.
In iterating L2norm reguralization, I want to update the PSF at the same time, and when I looked it up, I found a function called deconvblind
in Matlab:
l[J,PSF] = deconvblind(I,INITPSF) deconvolves image I using the maximum likelihood algorithm, returning both the deblurred image, J, and a restored point-spread function, PSF. The input array, I, and your initial guess at the PSF, INITPSF, can be numeric arrays or cell arrays. (Use cell arrays when you want to be able to perform additional deconvolutions that start where your initial deconvolution finished. See Resuming Deconvolution for more information.) The restored PSF is a positive array that is the same size as INITPSF, normalized so its sum adds up to 1.
Is there a function similar to deconvblind
in Python?
Here is how you can implement blind deconvolution in python with the Richardson Lucy algorithm:
Iterative updation steps for Blind Deblurring (as proposed in 2, 4), with unknown PSF H, corrupted image X and restored image S are shown in the below equation:
The following code shows my implementation of the iterative Bayesian blind deconvolution algorithm proposed in 1, mostly with frequency domain operations (as opposed to spatial domain implementation as in 3). It is similar to the non-blind implementation as in 3, only we need to estimate the unknown blur PSF at each iteration (starting with a random PSF), assumed to be known in 3.
import numpy as np
from scipy.signal import fftconvolve
def richardson_lucy_blind(image, psf, original, num_iter=50):
im_deconv = np.full(image.shape, 0.1, dtype='float') # init output
for i in range(num_iter):
psf_mirror = np.flip(psf)
conv = fftconvolve(im_deconv, psf, mode='same')
relative_blur = image / conv
im_deconv *= fftconvolve(relative_blur, psf_mirror, mode='same')
im_deconv_mirror = np.flip(im_deconv)
psf *= fftconvolve(relative_blur, im_deconv_mirror, mode='same')
return im_deconv
The next animation shows image restoration with non-blind and blind versions of the RL algorithm, respectively.