doc: fix English gramma in tutorial out-of-focus-deblur filter (#12214)
* doc: fix English gramma in tutorial out-of-focus-deblur filter * Update out_of_focus_deblur_filter.markdown slightly modified one sentence
This commit is contained in:
parent
0f2b535fcc
commit
f36790d521
@ -8,54 +8,54 @@ Goal
|
|||||||
|
|
||||||
In this tutorial you will learn:
|
In this tutorial you will learn:
|
||||||
|
|
||||||
- what is a degradation image model
|
- what a degradation image model is
|
||||||
- what is PSF of out-of-focus image
|
- what the PSF of an out-of-focus image is
|
||||||
- how to restore a blurred image
|
- how to restore a blurred image
|
||||||
- what is Wiener filter
|
- what is a Wiener filter
|
||||||
|
|
||||||
Theory
|
Theory
|
||||||
------
|
------
|
||||||
|
|
||||||
@note The explanation is based on the books @cite gonzalez and @cite gruzman. Also, you can refer to Matlab's tutorial [Image Deblurring in Matlab] and an article [SmartDeblur].
|
@note The explanation is based on the books @cite gonzalez and @cite gruzman. Also, you can refer to Matlab's tutorial [Image Deblurring in Matlab] and the article [SmartDeblur].
|
||||||
@note An out-of-focus image on this page is a real world image. An out-of-focus was done manually by camera optics.
|
@note The out-of-focus image on this page is a real world image. The out-of-focus was achieved manually by camera optics.
|
||||||
|
|
||||||
### What is a degradation image model?
|
### What is a degradation image model?
|
||||||
|
|
||||||
A mathematical model of the image degradation in frequency domain representation is:
|
Here is a mathematical model of the image degradation in frequency domain representation:
|
||||||
|
|
||||||
\f[S = H\cdot U + N\f]
|
\f[S = H\cdot U + N\f]
|
||||||
|
|
||||||
where
|
where
|
||||||
\f$S\f$ is a spectrum of blurred (degraded) image,
|
\f$S\f$ is a spectrum of blurred (degraded) image,
|
||||||
\f$U\f$ is a spectrum of original true (undegraded) image,
|
\f$U\f$ is a spectrum of original true (undegraded) image,
|
||||||
\f$H\f$ is frequency response of point spread function (PSF),
|
\f$H\f$ is a frequency response of point spread function (PSF),
|
||||||
\f$N\f$ is a spectrum of additive noise.
|
\f$N\f$ 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 \f$R\f$. Circular PSF is used in this work.
|
The circular PSF is a good approximation of out-of-focus distortion. Such a PSF is specified by only one parameter - radius \f$R\f$. Circular PSF is used in this work.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### How to restore an blurred image?
|
### How to restore a blurred image?
|
||||||
|
|
||||||
The objective of restoration (deblurring) is to obtain an estimate of the original image. Restoration formula in frequency domain is:
|
The objective of restoration (deblurring) is to obtain an estimate of the original image. The restoration formula in frequency domain is:
|
||||||
|
|
||||||
\f[U' = H_w\cdot S\f]
|
\f[U' = H_w\cdot S\f]
|
||||||
|
|
||||||
where
|
where
|
||||||
\f$U'\f$ is spectrum of estimation of original image \f$U\f$,
|
\f$U'\f$ is the spectrum of estimation of original image \f$U\f$, and
|
||||||
\f$H_w\f$ is restoration filter, for example, Wiener filter.
|
\f$H_w\f$ is the restoration filter, for example, the Wiener filter.
|
||||||
|
|
||||||
### What is Wiener filter?
|
### What is the 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,
|
The Wiener filter is a way to restore a blurred image. Let's suppose that the 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:
|
then a simplified Wiener formula is:
|
||||||
|
|
||||||
\f[H_w = \frac{H}{|H|^2+\frac{1}{SNR}} \f]
|
\f[H_w = \frac{H}{|H|^2+\frac{1}{SNR}} \f]
|
||||||
|
|
||||||
where
|
where
|
||||||
\f$SNR\f$ is signal-to-noise ratio.
|
\f$SNR\f$ is signal-to-noise ratio.
|
||||||
|
|
||||||
So, in order to recover an out-of-focus image by Wiener filter, it needs to know \f$SNR\f$ and \f$R\f$ of circular PSF.
|
So, in order to recover an out-of-focus image by Wiener filter, it needs to know the \f$SNR\f$ and \f$R\f$ of the circular PSF.
|
||||||
|
|
||||||
|
|
||||||
Source code
|
Source code
|
||||||
@ -68,36 +68,36 @@ You can find source code in the `samples/cpp/tutorial_code/ImgProc/out_of_focus_
|
|||||||
Explanation
|
Explanation
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
An out-of-focus image recovering algorithm consists of PSF generation, Wiener filter generation and filtering an blurred image in frequency domain:
|
An out-of-focus image recovering algorithm consists of PSF generation, Wiener filter generation and filtering a blurred image in frequency domain:
|
||||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp main
|
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp main
|
||||||
|
|
||||||
A function calcPSF() forms an circular PSF according to input parameter radius \f$R\f$:
|
A function calcPSF() forms a circular PSF according to input parameter radius \f$R\f$:
|
||||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcPSF
|
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcPSF
|
||||||
|
|
||||||
A function calcWnrFilter() synthesizes simplified Wiener filter \f$H_w\f$ according to formula described above:
|
A function calcWnrFilter() synthesizes the simplified Wiener filter \f$H_w\f$ according to the formula described above:
|
||||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcWnrFilter
|
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcWnrFilter
|
||||||
|
|
||||||
A function fftshift() rearranges PSF. This code was just copied from tutorial @ref tutorial_discrete_fourier_transform "Discrete Fourier Transform":
|
A function fftshift() rearranges the PSF. This code was just copied from the tutorial @ref tutorial_discrete_fourier_transform "Discrete Fourier Transform":
|
||||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp fftshift
|
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp fftshift
|
||||||
|
|
||||||
A function filter2DFreq() filters an blurred image in frequency domain:
|
A function filter2DFreq() filters the blurred image in the frequency domain:
|
||||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp filter2DFreq
|
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp filter2DFreq
|
||||||
|
|
||||||
Result
|
Result
|
||||||
------
|
------
|
||||||
|
|
||||||
Below you can see real out-of-focus image:
|
Below you can see the real out-of-focus image:
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
Below result was done by \f$R\f$ = 53 and \f$SNR\f$ = 5200 parameters:
|
And the following result has been computed with \f$R\f$ = 53 and \f$SNR\f$ = 5200 parameters:
|
||||||

|

|
||||||
|
|
||||||
The Wiener filter was used, values of \f$R\f$ and \f$SNR\f$ were selected manually to give the best possible visual result.
|
The Wiener filter was used, and values of \f$R\f$ and \f$SNR\f$ 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.
|
We can see that the result is not perfect, but it gives us a hint to the image's content. With some difficulty, the text is readable.
|
||||||
|
|
||||||
@note The parameter \f$R\f$ is the most important. So you should adjust \f$R\f$ first, then \f$SNR\f$.
|
@note The parameter \f$R\f$ is the most important. So you should adjust \f$R\f$ first, then \f$SNR\f$.
|
||||||
@note 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.
|
@note Sometimes you can observe the ringing effect in a restored image. This effect can be reduced with several methods. For example, you can taper input image edges.
|
||||||
|
|
||||||
You can also find a quick video demonstration of this on
|
You can also find a quick video demonstration of this on
|
||||||
[YouTube](https://youtu.be/0bEcE4B0XP4).
|
[YouTube](https://youtu.be/0bEcE4B0XP4).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user