in fourier domain in spatial domain linear filters non...
TRANSCRIPT
IE PŁ P. Strumiłło, M. Strzelecki
Image filtering
In Fourier domain In spatial domain
Linear filters Non-linear filters
IE PŁ P. Strumiłło, M. Strzelecki
Imagepreprocessing
Imagepreprocessing
Computer
+
program
+
Knowledge
base
Computer
+
program
+
Knowledge
baseIma
ge
acqu
isitio
n
• contrast enhancement
• noise reduction
• image sharpening
• image smoothing
• edge detection
• correction of geometricdistortions
An image processing system
IE PŁ P. Strumiłło, M. Strzelecki
Image filtering in spectrum domain
g(x,y) = IFFT H(u,v) Ff(x,y)
f(x,y) g(x,y)
Source
imageFFT2 IFFT2 Output
image
H(u,v)
IE PŁ P. Strumiłło, M. Strzelecki
22
0
0
),(
),( 0
),( 1),(
vuvuD
DvuD
DvuDvuH
+=
>
≤=
Ideal low-pass filter
D0
IE PŁ P. Strumiłło, M. Strzelecki
D0=10 D0=70
256x256
FFT
IE PŁ P. Strumiłło, M. Strzelecki
Image after ideal low-pass filtering, D0=70
IE PŁ P. Strumiłło, M. Strzelecki
Image after ideal low-pass filtering, D0=10
IE PŁ P. Strumiłło, M. Strzelecki
D0=70
D0=30
D0=10
Ideal low-pass filter - example
ringing
IE PŁ P. Strumiłło, M. Strzelecki
Butterworth filter
,...,nvu)v,u(D
]D/)v,u(D)[()v,u(H
n
21
121
1
22
20
=+=
−+=
,
D0
n- filter order
IE PŁ P. Strumiłło, M. Strzelecki
n = 1
Low-pass filtering
Butterworth filter
IE PŁ P. Strumiłło, M. Strzelecki
D0=70
D0=30
D0=10
n = 1
Low-pass Butterworth filter - examples
no ringing
IE PŁ P. Strumiłło, M. Strzelecki
22
0
0
1
0
vu)v,u(D
D)v,u(D
D)v,u(D)v,u(H
+=
>
≤=
Ideal high-pass filter
D0
IE PŁ P. Strumiłło, M. Strzelecki
D0=10 D0=70
Ideal high-pass filter - example
IE PŁ P. Strumiłło, M. Strzelecki
Image after ideal high-pass filtering, D0=10
IE PŁ P. Strumiłło, M. Strzelecki
,...,nvu)v,u(D
)]v,u(D/D)[()v,u(H
n
21
121
1
22
20
=+=
−+=
D0
n - filter order
High-pass Butterworth filter 2
IE PŁ P. Strumiłło, M. Strzelecki
D0=10 D0=70
n = 1
High-pass Butterworth filter - examples
IE PŁ P. Strumiłło, M. Strzelecki
n = 1
D0=10 D0=70
High-pass Butterworth filter - examples
IE PŁ P. Strumiłło, M. Strzelecki
Band-pass filter
IFFT
30
20
The filter selects narrow band
of image frequencies
FFT
IE PŁ P. Strumiłło, M. Strzelecki
Image filtering in spatial domain
Inputimage
2D convolutionOutput
image
h(x,y)
g(x,y) = h(x,y)**f(x,y) =
=IF H(u,v) F(u,v)
f(x,y) g(x,y)
IE PŁ P. Strumiłło, M. Strzelecki
0x0x
( )y,xf ( )y,xg
0y0y
The filtering result depends on the processed pixel
neighbourhood. This neighbourhood is call a
filtering window (or a filtering mask).
( )00 y,xfΩ
Image filtering in spatial domain
IE PŁ P. Strumiłło, M. Strzelecki
0x0x
( )lyy,kxxf ±± 00
( )y,xf ( )y,xg
0y0y
Image filtering in spatial domain
IE PŁ P. Strumiłło, M. Strzelecki
The result of filtering an image of size M x N for the filtering
window size (2k+1)x(2l +1) is an image of size (M -2k)x(N -2l)
k=2
l=2
( )y,xg
Boundary elements
IE PŁ P. Strumiłło, M. Strzelecki
f: array[0..M-1,0..N-1] of byte; //source image
g: array[0..M-1,0..N-1] of real; //filtered image
...
for x:=k to M-k-1 do
for y:=l to N-l-1 do
g(x,y):=P(f(x,y)); //perform local computations
end;
end;
( ) ( )1212 +×+ lk
Operator P [.] can be linear or nonlinear.
Correspondingly we define linear or nonlinear image filtering.
k=2
l=2
Filtering algorithm
IE PŁ P. Strumiłło, M. Strzelecki
Salt and pepper noise
0.05, i.e. 5% ofdistorted pixels
Source
Randomly selected pixels are assigned minimum ormaximum value randomly.
0.5, i.e. 20% ofdistorted pixels
IE PŁ P. Strumiłło, M. Strzelecki
σ2= 0.05 σ2=0.2Source
For each image pixel: ( ) ( ) ( )y,xny,xfy,xg +=
Gaussian noise
IE PŁ P. Strumiłło, M. Strzelecki
The Gauss distribution
0 100 200 300 400 500 600 700 800 900 1000-5
-4
-3
-2
-1
0
1
2
3
4
( ) ( )10,N,N =σµ
-5 -4 -3 -2 -1 0 1 2 3 40
5
10
15
20
25
30
35
40
( )( )
−−=
2
2
22
1
σ
µ
πσ
xexpxp
IE PŁ P. Strumiłło, M. Strzelecki
σ2= 0.05 σ2=0.2Source
( ) ( ) ( ) ( )y,xfy,xny,xfy,xg ⋅+=
Uniform noise
Multiplicative noise
For each image pixel:
IE PŁ P. Strumiłło, M. Strzelecki
-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.50
5
10
15
20
25
0 200 400 600 800 1000-0.5
0
0.5
Uniform noise
IE PŁ P. Strumiłło, M. Strzelecki
Linear filtering
( ) ( )[ ]( )( )
( )∑Ω∈
Ω++
==
fy,x
y,xflk
y,xfPy,xg1212
1
Operator P [.] is a linear function of neighbour pixels.
Example – an averaging filter
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
( ) ×=25
1l,kh
Filtering mask
∑Why coefficients = 1?
___
IE PŁ P. Strumiłło, M. Strzelecki
1
1
1
1
1
1
1
1
1
3
18
1
15
9
71
2
22
5
3
18
1
15
9
71
2
22
5
1 *
1*
1*
1*
1*
1*
1*
1*
1*
3
18
1
15
146
71
2
22
5
Multiplication of filtercoefficient by thecorrecsponding image pixels
Filtering maskImage
Image filtering – calculations
IE PŁ P. Strumiłło, M. Strzelecki
f, g : array[0..N-1, 0..N-1] of byte;
size2 – half size of the mask
h : array[-size2..size2,-size2..size2] of integer;
...
for i:=1 to N-2 do for j:=1 to N-2 do
begin
g[i,j]:=0;
for k:=-size2 to size2 do for l:=-size2 to size2 do
g[i,j]:=g[i,j] + f[i+k,j+l] * h[i+k,j+l];
end;
...Range check g[i,j] !!!
Image filtering – the algorithm
IE PŁ P. Strumiłło, M. Strzelecki
( ) ( ) ( ) ( ) ( )lx,kxfl,khy,xfy,xhy,xg
k l
−−=∗= ∑ ∑∞
−∞=
∞
−∞=
Linear filtering of an image is given by performing 2D
convolution of an image with the filtering mask
Convolution in 2D
Filteringmask
Image
IE PŁ P. Strumiłło, M. Strzelecki
eg. for a 512x512 image 510*510*9 = 2 340 000 multiplications and additions need to be calculated
( ) ( ) ( )
( ) ( ) ( ) ( ) ( ) ( )( ) ( ) ( ) ( ) ( ) ( )( ) ( ) ( ) ( ) ( ) ( )11111101111
10100101
11111101111
1
1
1
1
−−+−+−+−+
+−+++−+
++−−++−+++−−=
=−−= ∑∑−= −=
y,xf,hy,xf,hy,xf,h
y,xf,hy,xf,hy,xf,h
y,xf,hy,xf,hy,xf,h
ly,kxfl,khy,xg
k l
For a 3x3 filtering mask at each (x,y) image pixel
coordinate the following calculations take place:
Convolution in 2D
IE PŁ P. Strumiłło, M. Strzelecki
( ) ( ) ( )ly,kxfl,khy,xg
k l
−−= ∑∑−= −=
1
1
1
1
( )y,xf
( )00,h
( )11 −− ,h
( )11,h
( )11 −,h
( )11,h −
y
x
−
−
1
1
y
x
+
+
1
1
y
x
+
−
1
1
y
x
−
+
1
1
y
x
y
x
−
−
1
1
y
x
+
+
1
1
y
x
+
−
1
1
y
x
−
+
1
1
y
x
y
x
−
−
1
1
y
x
+
+
1
1
y
x
+
−
1
1
y
x
−
+
1
1
y
x
( )l,kh*
( )ly,kxf −−
Convolution in 2D
IE PŁ P. Strumiłło, M. Strzelecki
Averaging = low pass filter
=
111
111
111
9
11h
=
11111
11111
11111
11111
11111
25
12h
Can one use mask of even size ?
IE PŁ P. Strumiłło, M. Strzelecki
Frequency characteristics of low pass filters
for 5x5 mask for 3x3 mask
IE PŁ P. Strumiłło, M. Strzelecki
Low-pass filtering the image
Source image
5x5 mask
3x3 mask
IE PŁ P. Strumiłło, M. Strzelecki
The Gaussian filter
Gaussian filters on a
discrete grid
1
2
1
2
4
2
1
2
1
×16
1
Integer coefficients
require less computations
0
1
2
1
0
1
6
6
1
16
10
1
6
6
1
0
1
2
1
0
2
2
10
10
10×96
1
( )
+−=
2
22
2 22
1
σπσ
yxexpy,xp
IE PŁ P. Strumiłło, M. Strzelecki
Image filtering using the Gaussian filter
source image filtered image
IE PŁ P. Strumiłło, M. Strzelecki
Smoothing filters - comparison
Gaussian 5x5, σσσσ=1 Averaging 5x5Source
IE PŁ P. Strumiłło, M. Strzelecki
Image low-pass filters - examples
Image distorted by the
Gaussin noise N(0, 0.01)Low pass filter 3x3
Butterworth filter D0=50Gaussian filter 3x3
for grayscale
<0,1>
IE PŁ P. Strumiłło, M. Strzelecki
low-pass filter 5x5
Gaussian filter 5x5 Butterworth filter D0=30
Image low-pass filters - examples
Image distorted by the
Gaussian noise N(0, 0.01)
IE PŁ P. Strumiłło, M. Strzelecki
Image low-pass filters - examples
Image distorted by the
Gaussian noise N(0, 0.002)Low pass filter 3x3
Butterworth filter D0=50Gaussian filter 3x3
IE PŁ P. Strumiłło, M. Strzelecki
For ∆x=1:
( )xf
( )x
f
dx
dfx'f
∆
∆≅=
( ) ( ) ( )y,xfy,xfx
fx'f 1+−=
∆
∆≅
Corresponds to a filter mask:
-11
Similarily for y (∆y=1) :
-1
1
Image sharpening filters
IE PŁ P. Strumiłło, M. Strzelecki
Gradient images
-11
-1
1
First order gradient filters
An image of retinal arteries
IE PŁ P. Strumiłło, M. Strzelecki
0
-1
0
-1
4
-1
0
-1
0
How to work out this filter mask?
Hint: compute second order image differences along
columns and rows and add the results
Second order gradient filters
IE PŁ P. Strumiłło, M. Strzelecki
0
-1
0
-1
5
-1
0
-1
0
An original image was added to the second order gradient mask:
0
-1
0
-1
4
-1
0
-1
0
0
0
0
0
1
0
0
0
0
0
-1
0
-1
5
-1
0
-1
0
=+
Second order image sharpening filter
IE PŁ P. Strumiłło, M. Strzelecki
0
-1
0
-1
8
-1
0
-1
0
Please compute coefficients of this filter
The Laplace filter
IE PŁ P. Strumiłło, M. Strzelecki
0
-1
0
-1
9
-1
0
-1
0
-1
-1
-1
-1
8
-1
-1
-1
-1
0
0
0
0
1
0
0
0
0
-1
-1
-1
-1
9
-1
-1
-1
-1
=+
The Laplace filter
An original image was added to the second order gradient mask:
IE PŁ P. Strumiłło, M. Strzelecki
−
−−
−
=
010
151
010
3'
h
−−−
−−
−−−
=
111
191
111
4'
h
Comparison of sharpening filters
IE PŁ P. Strumiłło, M. Strzelecki
( )y,xf
( )y,xf smooth
( ) ( ) ( )y,xfy,xfy,xg smooth−=
( ) ( ) ( ) ( ) ( )y,xfy,xfy,xfy,xgy,xg smoothum −=+= 2
Unsharp masking filter
IE PŁ P. Strumiłło, M. Strzelecki
( )y,xf
( ) ( ) ( ) ( ) 11 <−−= ααα ,y,xfy,xfy,xg smoothum
1-α
α
smoothing
+( )y,xf ( )y,xgum
+
_
Parametr α decides about thesharpening strength.
Unsharp masking filter
IE PŁ P. Strumiłło, M. Strzelecki
α=2/3
Unsharp masking filter
IE PŁ P. Strumiłło, M. Strzelecki
Blurred image Sharpened image
%MATLABout_image = filter2(filter_mask, in_image);
High-pass filters
IE PŁ P. Strumiłło, M. Strzelecki
Filtering in spectrum domain
FFTIFFT
=
Low-pass filter spectrum
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
×100
1
Filter mask
IE PŁ P. Strumiłło, M. Strzelecki
( ) ( )( )µσ
σµ −
−+= y,xf
ny,xg
2
22
Noisy image(Gaussian noise)
Wiener filter Averaging filter
where:
n2 – noise variance
µ – mean of image pixels in a window
σ2 – image variance
For: ( ) ( )y,xfy,xg,n ≅≅ 0
( ) µσ ≅≅ y,xg,n
The Wiener adaptive filter
IE PŁ P. Strumiłło, M. Strzelecki
Nonlinear filters
NO
The filtered image is defined by a
non-linear function of the source image
Can we compute spectral
characteristics for nonlinear filters?
Because transfer characteristics of nonlinear
filters depend on image content itself!
IE PŁ P. Strumiłło, M. Strzelecki
Median filter (order statistic filter)
The median m of a set of values (e.g.
image pixels in the filtering mask) is such
that half the elements in the set are less
than m and other half are grater than m.
x(n)=1, 5, -7, 101, -25, 3, 0, 11, 7
Sorted sequence of elements:
xs(n)=-25, -7, 0, 1, 3, 5, 7, 11, 101
median
IE PŁ P. Strumiłło, M. Strzelecki
f(x,y) g(x,y)g(x,y)=medianf(x,y); (x,y)∈∈∈∈hf(x,y)
Median filtering the image
source image f output image g
h
IE PŁ P. Strumiłło, M. Strzelecki
1 2 3 4 5 6 7 8 (iterations)
44 06 06 06 06 06 06 0655 44 12 12 12 12 12 1212 55 44 18 18 18 18 1842 12 55 44 42 42 42 4294 42 18 55 44 44 44 4418 94 42 42 55 55 55 5506 18 94 67 67 67 67 6767 67 67 94 94 94 94 94
Unsorted sequence
Bubble-sort algorithm
© N. Wirth, „Algorithms+Data Structures=Programs”
IE PŁ P. Strumiłło, M. Strzelecki
a[k], k=1..N – unsorted sequencefor i:=2 to N dobegin
for j:=N downto i doif a[j-1]>a[j] then
beginx=a[j-1]; a[j-1]:=a[j]; a[j]:=x;end;
end;
Bubble-sort program
IE PŁ P. Strumiłło, M. Strzelecki
Demo – median filter
Source image distorted by
„salt and pepper noise”
Enhanced image using
the median filter (3x3)”
%MATLABout_image = medfilt2(in_image, [m n]);
IE PŁ P. Strumiłło, M. Strzelecki
Median filter
Median filter:
1. Excellent in reducing impulsive noise (of size
smaller than half size of the filtering mask)
2. Keeps sharpness of image edges (as
opposed to linear smoothing filters)
3. Values of the output image are equal or
smaller than the values of the input image
(no rescaling required)
4. Large computing cost involved
IE PŁ P. Strumiłło, M. Strzelecki
Median filter
median average
[1 x 3] 1/3*[1 1 1]
IE PŁ P. Strumiłło, M. Strzelecki
MATLAB Demo – median filter
IE PŁ P. Strumiłło, M. Strzelecki
Filters
Smooth
Sharpen
Convolve
Gaussian Blur
Median
Mean
Unsharp mask
ImageJ