An out-of-focus image on this page is a real world image. An out-of-focus was done manually by camera optics.
What is a degradation image model?
A mathematical model of the image degradation in frequency domain representation is:
\[S = H\cdot U + N\]
where \(S\) is a spectrum of blurred (degraded) image, \(U\) is a spectrum of original true (undegraded) image, \(H\) is frequency response of point spread function (PSF), \(N\) is a spectrum of additive noise.
Circular PSF is a good approximation of out-of-focus distortion. Such PSF is specified by only one parameter - radius \(R\). Circular PSF is used in this work.
Circular point spread function
How to restore an blurred image?
The objective of restoration (deblurring) is to obtain an estimate of the original image. Restoration formula in frequency domain is:
\[U' = H_w\cdot S\]
where \(U'\) is spectrum of estimation of original image \(U\), \(H_w\) is restoration filter, for example, Wiener filter.
What is Wiener filter?
Wiener filter is a way to restore a blurred image. Let's suppose that PSF is a real and symmetric signal, a power spectrum of the original true image and noise are not known, then simplified Wiener formula is:
\[H_w = \frac{H}{|H|^2+\frac{1}{SNR}} \]
where \(SNR\) is signal-to-noise ratio.
So, in order to recover an out-of-focus image by Wiener filter, it needs to know \(SNR\) and \(R\) of circular PSF.
Source code
You can find source code in the samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp of the OpenCV source code library.
Below result was done by \(R\) = 53 and \(SNR\) = 5200 parameters:
The restored (deblurred) image
The Wiener filter was used, values of \(R\) and \(SNR\) were selected manually to give the best possible visual result. We can see that the result is not perfect, but it gives us a hint to the image content. With some difficulty, the text is readable.
Note
The parameter \(R\) is the most important. So you should adjust \(R\) first, then \(SNR\).
Sometimes you can observe the ringing effect in an restored image. This effect can be reduced by several methods. For example, you can taper input image edges.
You can also find a quick video demonstration of this on YouTube.