Deconvolution in Python

I am trying to implement code from a paper in Python. One of the steps it uses is shrinking kernel blind deconvolution.
-I decided to use skimage.restoration.richardson_lucy - is anyone aware of anything better?
-how can I get rid of ‘ringing artifacts’ on the edges? I tried the trick from original paper, to append mirrored image on two sides. This makes the image effectively periodic, but anyway the artifacts disappear only on 2 of 4 edges
-are you aware of any shrinking kernel deconvolution implementation that I could use or study as an example?

1 Like

Hi @mpawlowska

I’ve been working on a deconvolution project that has python and imagej wrappers for a few years. Huge disclaimer… .my project is mostly experimental code, and the purpose is to work out a build system for projects that use low level math libaries in c++ (built on MKL, Cuda, OpenCL, and ArrayFire) to be called from high level applications (in java and python).

An example calling deconvolution from python is here. It’s a complicated project with a lot of moving parts. However if you think it is useful, perhaps start by providing example images and PSF (Point Spread Function), and I’d by happy to test my code on them.

I know a few groups are working on similar things, and have a more user-friendly/mature python frame work, @talley comes to mind, so perhaps he can point you to some useful/mature code.

Some more specific answers to your questions…

  1. Richardson Lucy is probably the most commonly used deconvolution algorithm, it works well in most cases, especially if noise is relatively low, and you are able to create a reasonably accurate PSF. The standard Richardson Lucy algorithm is not “blind”, so you need to create the PSF using a theoretical model, or by measuring it.

  2. I am not familiar with the “shrinking kernel blind deconvolution”. Blind deconvolution in general is used when you cannot create a theoretical PSF or measure the PSF. However this is a non-trivial and controversial method. There isn’t a lot of scientific evidence that blind deconvolution converges. Meaning there are not experiments, where someone measured the PSF, then did a blind deconvolution with the same system, and showed the blind deconvolution converged to the system PSF. Is there a reason that blind deconvolution was used in your project instead of measuring the PSF or using a theoretical PSF??

  3. To deal with edges I use a “non-circulant” approach. It ussually works quite well. If you are able to share image and PSF I can run some tests for you.



thanks for the long answer. I am aware that blind deconvolution will be imperfect by definition. Maybe I should specify that I’m trying to rewrite this in Python:

and specifically, I’m struggling with this:

and now I see why I can’t find anything about the “shrinking kernel” method: it is cited as
“X. Yi and S. Weiss, “An iterative deconvolution method for fluorescence microscopy with shrinking kernel (DeconvSK),” in preparation (2019).”
From the code, they are running deconvblind with narrowing Gauss.

So, which function in Python if any would give me something comparable to Matlabs deconvblin?

You write that Richardson-Lucy is not blind, but in the example given in skimage, deconvolution is initialized with a “flat” psf:
and after some iterations the image is restored, which is why I decided to start there.

Best regards.

Hi @mpawlowska

In the example you shared the PSF is initialized as a 5 by 5 squared of ones

psf = np.ones((5, 5)) / 25
astro = conv2(astro, psf, 'same')
# Add Noise to Image
astro_noisy = astro.copy()
astro_noisy += (np.random.poisson(lam=25, size=astro.shape) - 10) / 255.

# Restore Image using Richardson-Lucy algorithm
deconvolved_RL = restoration.richardson_lucy(astro_noisy, psf, iterations=30)

Note the image is first convolved with the PSF, noise is added, then it is deconvolved with the same PSF. The ‘flat’ PSF is used for the convolution (simulation) and deconvolution. It isn’t changed during the process.

Is it possible for you to measure or calculate the PSF of your instrument??

I am not aware of any blind deconvolution in python.

1 Like

Aaaaaah, okay. Now I understand. Thank you for clarifying this for me. So my choice is

  1. get hold of a Matlab license (my institute has some but limited and with hoops to jump) OR
  2. are there any other user-friendly open-source options?

I’m not aware of any open source blind deconvolution. It is a “relatively” easy algorithm to implement, and the MATLAB code is actually open. So you could study it and re-implement if you really need blind deconvolution in Python. Though jumping through hoops for a MATLAB license is probably much.

Do you know how the original authors got to the starting point for the PSF?? Is there a reason the original authors think the PSF needs further adjustment by the blind approach?? Do you think the results would change much if you used fixed PSF deconvolution??


Hi everyone,

Sorry for the delay in responding. Turns out I have notifications for “scikit-image” but not “skimage”. :man_facepalming:

We have a long-standing pull request to scikit-image implementing blind deconvolution. I can try to push it through in the coming days, but in the meantime, you can probably just grab the source code from the pull request directly. It’s a quite simple modification to Richardson Lucy in the end:

1 Like

I just tried to add #skimage as a tag synonym to #scikit-image, but it seems to only have worked half way: the tag description page redirects to scikit-image now, but the tags weren’t replaced on the posts, and I got an Internal Server Error notification.

As there were just three posts with skimage, I now replace this tag by scikit-image on those posts.

Thanks @jni! I’ll try.

Hey @jni, I needed the blind deconvolution for one of my project and follow the comments (mostly yours) on the pull request you cited to clean it. I wonder if it’s still of interest for scikit-image? and if so, should I push my changes into a new PR?

1 Like

Hi @bioimage-analysis and @jni

How did you test that the blind deconvolution converges?? Many, many years ago I worked on a product called Autoquant which offerred a blind deconvolution option. I had concerns about the convergence of the “bllind” algorithm which I’ve expressed here. To my knowledge no one has ever presented data that shows the Richardson Lucy blind deconvolution converges for microscopy data. (other approaches, such as parimetric approaches, or a deep learning approach may have more promise, but still lack proof as far as I know).

The “blind” algorithm in Autoquant required full meta data to generate a starting point. If sperical aberration was present it required a preprocessing step to detect SA. It wasn’t really even “blind”.

Did you output the PSF and check it against a theoretical model or measured PSF?? Did you do simulations where you started with an obviously incorrect PSF and check if it converged to a known simulated PSF? It would be interesting if you output the PSF at every iteration and show the convergence.

Even if the PSF converges you still have to show co-convergence of the image. Keep in mind with blind deconvolution at early iterations you will be deconvolving with an incorrect PSF, until the PSF converges. Does the image converge along with the PSF?

It’s complicated and at the very least requires output of all intermediate iterations to prove it is really converging.

1 Like

Hi @bnorthan,

Thank you for your comment, I did use autoquant in the past but I am definitely not an expert in deconvolution. The algorithm is following a paper you certainly know from Fish et al. and nothing more. I had a pretty naive approach were I though I could try it on widefield microscope image to recover the psf. I should add that the code was alredy written by someone else, I barely cleaned it following @jni advices.
My experience has been that it can converge if there is a very simple object in the image (like the cross they use in the paper). But it less clear, even with the example from scikit-image, it starting converging but then psf became unrealistically large.

1 Like