Perform an image deconvolution using FFTs and Python

Click For Summary
SUMMARY

The discussion focuses on performing image deconvolution using Fast Fourier Transforms (FFTs) in Python, specifically utilizing the NumPy library. The problem involves a Gaussian point spread function defined by $$f(x, y) = e^{-\frac{x^2 + y^2}{2 \sigma^2}}$$ with ##\sigma = 25##, applied to a 1024 x 1024 blurry image. The user has implemented the Fourier transforms using NumPy's rfft2 and irfft2 functions, but encounters issues with the quality of the deconvolved image, suspecting errors in the density plot or the blurred image itself.

PREREQUISITES
  • Understanding of Fourier Transforms, specifically rfft2 and irfft2 functions in NumPy.
  • Familiarity with Gaussian functions and their application in image processing.
  • Experience with Python programming and the NumPy library.
  • Knowledge of image representation as 2D arrays in Python.
NEXT STEPS
  • Explore the implementation of Gaussian point spread functions in image processing.
  • Learn about the effects of convolution on images and how to reverse it using deconvolution techniques.
  • Investigate the use of smaller test images (e.g., 16x16 arrays) to troubleshoot deconvolution processes.
  • Review the principles of density plots and their role in visualizing Gaussian functions.
USEFUL FOR

Data scientists, image processing engineers, and Python developers interested in enhancing image quality through deconvolution techniques using FFTs.

kaashmonee
Messages
7
Reaction score
1

Homework Statement


[/B]
This problem is from Mark Newman's Computational Physics, problem 7.9, found at
http://www-personal.umich.edu/~mejn/cp/exercises.html. The problem gives us a blurry convolved image, according to a Gaussian point spread function and our objective is to deconvolve it to obtain a non-blurry image. The blurry image is given to us in a text file that we read into a numpy array, and the Gaussian point spread function is as follows: $$f(x, y) = e^{-\frac{x^2 + y^2}{2 \sigma^2}},$$ where ##\sigma = 25##.

In part a), we are given a 1024 x 1024 image that we read into a numpy array. In part b), we create a density plot, of the same dimensions as the original photo, (1024 x 1024) using the Gaussian point spread function. We imagine a mesh where the ##x## and ##y## axes both go from [-512, 511], which is what we use to create our density plot.

The third part requests that we perform the Fourier transforms using the rfft2 and irfft2 numpy functions by reading in the blurred photo, calculating the point spread function, Fourier transforming both, dividing one by the other, and finally performing an inverse transform to get the unblurred photo and displaying it on the screen.

Homework Equations


The Gaussian point spread function: $$f(x, y) = \text{exp}\Big(- \frac{x^2 + y^2}{2 \sigma^2}\Big), \sigma = 25.$$

The Attempt at a Solution


I'm attaching my GitHub repo with my solution here: (https://github.com/kaashmonee/image-deconvolution/blob/master/decon.ipynb) I've solved most parts of the problem so far. But, for some reason, the deconvolved image seems to not show anything very useful. Since my deconvolved image only really depends on my density plot and the blurred image, I have to guess that there is an issue with the way I've made my density plot since the blurred image seems to look okay.

In order to create my density plot, I've constructed a mesh that goes from [-512, 511] on the x and y axes. I then, for each location in the mesh, save the result of applying the point spread function, and get the pattern that we are supposed to see, according to the book. The function is not very complicated, so I am failing to see where I would be going wrong. I set up the axes correctly and the density plot correctly (or so it seems), so I am guessing that there is perhaps a more nuanced error within either my density plot or my blurred image which I am unable to identify at the moment.

Thank you very much.
 
Technology news on Phys.org
I visited your github link, but I don't have time at the moment to review all of your code. This definitely looks like an interesting problem.
Perhaps you could get another 1024 x 1024 known image then try to convolve it with the function, to make sure you are doing it right, then try to reconstruct the image back to what you originally had. Or try a small Numpy array of numbers, something like a 16x16, or even smaller. This may reveal something.
 
  • Like
Likes   Reactions: kaashmonee

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K