You are on page 1of 19

Università del Salento and INFN Lecce

Introduction to Wiener Filtering

Mosè Giordano

26 November 2014
The purpose of Wiener filtering

Reduce degradation and noise in images, audio signals, etc.

Degradation Filtering

Picture of the Moon taken by the Galileo spacecraft on 7 December 1992

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 2 / 19
The theory

Suppose you have a signal S(t) in the time domain (whatever “time” is: actual
time, point in space, pixel of an image, etc), degraded by known blurring
shift-invariant function B(t) and additive noise N(t)

X(t) = (B ∗ S)(t) + N(t)

The Fourier transform in the frequency domain of this degraded signal X(t) is

X̂(f ) = F (X)(f ) = B̂(f )Ŝ(f ) + N̂(f )

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 3 / 19
The theory (cont.)
We want to find an appropriate filter W(f ) such that the function W(f )X̂(f ) is
as much close as possible to the Fourier transform of the original signal
Ŝ(f ) = F (S)(f ), i.e. we want to minimize the quantity
D E D E
W(f )X̂(f ) − Ŝ(f ) = W(f )(B̂(f )Ŝ(f ) + N̂(f )) − Ŝ(f )

This condition is fulfilled by

B̂ ∗ (f )
W(f ) =
|B̂(f )|2 + |N̂(f )|2 /|Ŝ(f )|2

This is the Wiener filter function and F −1 (W X̂)(t) is the filtered signal. This
function gives more importance to frequencies with higher signal to noise
ratio. In absence of blurring

|Ŝ(f )|2
W(f ) =
|Ŝ(f )|2 + |N̂(f )|2

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 4 / 19
The theory (cont.)

Theoretically, in order to calculate the Wiener filter function we need to know


• the original signal
• the blurring function
• the noise
or at least their power spectra. Actually, power spectra need not to be known
exactly (noise power spectrum can often be easily estimated, e.g. white noise
has constant spectrum) because
• most signals of the same class have fairly similar power spectra
• the Wiener filter is insensitive to small variations in the original signal
power spectrum
We can estimate the original signal power spectrum using a representative of
the class of signals being filtered

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 5 / 19
Wiener filter applied to a temporal signal
IDL/GDL code:
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;; Temporal Signal ;;;;;;;;;
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ntime = 1001
ff = 100
;; Define the times array.
time = findgen(ntime)/ff
;; The orignal signal.
sign = sin(time) - 0.7 * cos (0.7 * time) + 0.5 * sin (0.5 * time)^2
;; The noise.
noise = 0.3 * randomu(null , ntime) * cos (10 * randomu(null , ntime) * time)
;; Signal + noise.
sign_noise = sign + noise
;; Its Fourier transform.
ft = fft(sign_noise)

;; Determine the power spectra of the signal and the noise.


signal_power_spectrum = abs(fft(sign))^2
noise_power_spectrum = abs(fft(noise))^2
;; Calculate the Wiener filter.
filter = signal_power_spectrum /( signal_power_spectrum + noise_power_spectrum )
;; Get the filtered signal + noise.
result = fft(ft * filter , /inverse)

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 6 / 19
Wiener filter applied to a temporal signal (cont.)
1.5
Original signal

0.5

−0.5

−1
0 2 4 6 8 10
Time
Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 7 / 19
Wiener filter applied to a temporal signal (cont.)
1.5
Original signal
Noisy signal
1

0.5

−0.5

−1
0 2 4 6 8 10
Time
Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 8 / 19
Wiener filter applied to a temporal signal (cont.)

0.1 |Ŝ|2
|N̂|2
0.01

0.001

0.0001

1 × 10−5

1 × 10−6

1 × 10−7

1 × 10−8
−300 −200 −100 0 100 200 300
Frequency

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 9 / 19
Wiener filter applied to a temporal signal (cont.)

1
Wiener filter

0.1

0.01

0.001

0.0001

1 × 10−5
−300 −200 −100 0 100 200 300
Frequency

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 10 / 19
Wiener filter applied to a temporal signal (cont.)
1.5
Original signal
Filtered noisy signal
1

0.5

−0.5

−1
0 2 4 6 8 10
Time
Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 11 / 19
Wiener filter applied to an image
IDL/GDL code:
; ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;; Image ;;;;;;;;;
; ;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Read the Lena image.
read_jpeg , "lena.jpg", lena , /grayscale
;; Add a large noise to Lena.
img_noise = 1.8d * mean(lena) * randomu(systime (/ seconds), 512, 512)
degraded_img = lena + img_noise
;; Fourier transform of the degraded image.
ftimg = fft(degraded_img)

;; For the Wiener filter , use a completely different picture.


read_jpeg , "elaine.jpg", elaine , /grayscale
;; Determine the power spectrum of Elaine.
elaine_power_spectrum = abs(fft(elaine))^2
;; To further increase entropy , calculate a new noise.
img_noise_new = 2d * mean(lena) * randomu(systime (/ seconds), 512, 512)
;; Power spectrum of the new noise.
img_noise_power_spectrum = abs(fft( img_noise_new ))^2

;; Calculate the Wiener filter.


filter = elaine_power_spectrum /( elaine_power_spectrum + $
img_noise_power_spectrum )
;; Get the filtered picture.
result_img = fft(ftimg * filter , /inverse)

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 12 / 19
Wiener filter applied to an image (cont.)

The original image, file lena.jpg


Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 13 / 19
Wiener filter applied to an image (cont.)

The image has been degraded with a large noise


Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 14 / 19
Wiener filter applied to an image (cont.)

The picture used to filter the degraded image, file elaine.jpg


Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 15 / 19
Wiener filter applied to an image (cont.)

We can use a different picture to filter the degraded image because they
have similar power spectra
500 100000 500 100000
’lena.dat’ matrix ’elaine.dat’ matrix

10000 10000
400 400
1000 1000

300 100 300 100

10 10
200 200

1 1
100 100
0.1 0.1

0 0.01 0 0.01
0 100 200 300 400 500 0 100 200 300 400 500

Left: power spectrum of lena.jpg file; right: power spectrum of elaine.jpg file

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 16 / 19
Wiener filter applied to an image (cont.)
1

0.1

0.01

0.001

The Wiener filter function in the frequency domain

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 17 / 19
Wiener filter applied to an image (cont.)

The filtered image


Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 18 / 19
References and further reading

S. Eddins. Image deblurring – Wiener filter. Nov. 2, 2007. url:


http://blogs.mathworks.com/steve/2007/11/02/image-
deblurring-wiener-filter/.
W. Press. Computational Statistics with Application to Bioinformatics –
Unit 19: Wiener Filtering (and some Wavelets). 2008. url:
http://www.nr.com/CS395T/lectures2008/19-WienerFiltering.pdf.
E. Turkel. Summary Wiener Filter. 2004. url:
http://www.math.tau.ac.il/~turkel/notes/wiener7-2.pdf.
WIENER_FILTER (IDL Reference). url:
http://www.exelisvis.com/docs/WIENER_FILTER.html.

Mosè Giordano (UniSalento and INFN Lecce) Introduction to Wiener Filtering 26 November 2014 19 / 19

You might also like