Is there a function in Python similar to Matlab's deconvblind?

Question:

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?

Asked By: Super Saiyan

||

Answers:

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:

enter image description here

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.

enter image description here
References:

  1. https://courses.cs.duke.edu/cps258/fall06/references/Nonnegative-iteration/Richardson-alg.pdf
  2. https://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.richardson_lucy
  3. https://arxiv.org/ftp/arxiv/papers/1206/1206.3594.pdf
Answered By: Sandipan Dey

Nice Answer, but getting the PSF value in the of each iterration

psf *= fftconvolve(relative_blur, im_deconv_mirror, mode=’same’)

We are getting "operands could not be broadcast together with shapes (5,5) (480,640) (480,640)" issue,

Since the size of the relative_blur(480,640) and im_deconv_mirror(480,640) post convl and multiplying with psf*fftcov() it will give error right. Can you provide an example what would the size of each of this and psf final value and size would be

Answered By: sricharan