Image filtering in spatial domain

30
Image filtering In Fourier domain In spatial domain Linear filters Non-linear filters

Transcript of Image filtering in spatial domain

Page 1: Image filtering in spatial domain

Image filtering

In Fourier domain In spatial domain

Linear filters Non-linear filters

Page 2: Image filtering in spatial domain

Image filtering in spatial domain

Inputimage 2D convolution

Outputimage

h(x,y)

g(x,y) = IF{ H(u,v) F{f(x,y)} } =

IF {H(u,v)}** IF {F {f(x,y)} } = h(x,y)**f(x,y)

f(x,y) g(x,y)

Page 3: Image filtering in spatial domain

Filter definition in spatial domain

IF{H(u,v)}=h(x,y)

� �� �� �� � �� � �� � � F(�(x,y)) = �(x,y) � H(x,y)

���

� ��

� � � � � �

�(x,y) �

Page 4: Image filtering in spatial domain

I(i,j)

I(i-1,j-1) I(i-1,j) I(i-1,j+1)

I(i,j+1)I(i,j-1)

I(i+1,j-1) I(i+1,j) I(i+1,j+1)

h(-1,-1) h(-1,0) h(-1,1)

h(0,1)

h(1,1)h(1,0)h(1,-1)

h(0,-1) h(0,0)

Image and the filer mask convolution

This is true for symmetric masks only !

Page 5: Image filtering in spatial domain

��� � � ��� � ���� � �� ��� � �� � ��� � ���� � �

Computing the filtered image

� � � � � � �� � �� � � � �� � � �� � �� �

Page 6: Image filtering in spatial domain

���� � �

Boundary effects

� � � � � � �� � �� � � � �� � � �� � �� �

Page 7: Image filtering in spatial domain

��� � �

� � � � � � � � � � � � � � � � � � � ! � � � � � ��� � �� � � �

� � � � � �� � � � � ��� �� �� � � � �� � �� �� � � � �" � � #$ ��� #$ �

Boundary effects – 3x3 mask

Page 8: Image filtering in spatial domain

� ��� � � � � %&'' #( &'' #( )� � * � �� +

, � �" � $ - �� � � �" � � � ��� � � � � .

��� � � � � %#� �" � $ ''� �" � $ #� �" � $ ''� �" � $ )� � �� �� �� � +

'''

�� � ��� ( �� #$ � � �� � /�� ( �� #$ � �

* � ���

�%� /)�� &+

�� � � �� #� �" � $ �� � �" � $ � � �� � �� #� �" � $ �� � �" � $ � �

�%� /)�� �%� /)0 �%�0 � /0 )� �%�0 � /0 )+

� � � +

'''1 � � �� � �� � � �%� /)222

Image filtering – the algorithm

Page 9: Image filtering in spatial domain

Low pass filter

���

���

=111111111

91

1h

������

������

=

1111111111111111111111111

251

2h

3 � � � � � � � � � � � � � � � 4 � � � �" � �

Page 10: Image filtering in spatial domain

Frequency characteristics of low pass filters

�� � � �� � � � � �� � ���� � � �

H=freqz(h,m,n)

Page 11: Image filtering in spatial domain

Low-pass filtering the image

5 � � � � � �� � ��

� �� � � � �

���� � � �

Page 12: Image filtering in spatial domain

Gaussian filter

20

22 )(

),( d

yx

eyxh

+π−

=

����������������������

��������������������

���������������

���

���

=01130.

h

Nvud

evuH)( 222

0

),(+π−

=

���

���

=121242121

h

Page 13: Image filtering in spatial domain

Image filtering using the Gaussian filter

� � � � � � �� � �� �� �� � � � �� � ��

Page 14: Image filtering in spatial domain

Image low-pass filters - examples

6� � �� � �� �� � �� � * � ���

7 � � � � �� � � �� � �& &'&( �8 � ! � � � � �� �� � ���

� � ��� � ! � � �� �� �� � 9&� � &7 � � � � �� � �� �� � ���

�� � � � � �� ��

� � �� �

Page 15: Image filtering in spatial domain

� ! #� � � � �� �� � � ��

7 � � � � �� � �� �� � � �� � � ��� � ! � � �� �� �� � 9&� �&

Image low-pass filters - examples

6� � �� � �� �� � �� � * � ���

7 � � � � �� � � � �� � �& &'&( �

Page 16: Image filtering in spatial domain

Image low-pass filters - examples

6� � �� � �� �� � �� � * � ���

7 � � � � �� � � � �� � �& &'&&$ �8 � ! � � � � �� �� � ���

� � ��� � ! � � �� �� �� � 9&� � &7 � � � � �� � �� �� � ���

Page 17: Image filtering in spatial domain

High-pass filters (derivative filters)

���

���

−−−−−−−−

=111181111

1h

���

���

−=170670170670333670170670170

2

...

...

...

h

� � � � �� �

Page 18: Image filtering in spatial domain

High-pass filtering the image

mask h1 mask h2

Page 19: Image filtering in spatial domain

1 ),,(),()1(

),(),(),()1(

),(),(),(

),(),(),(

≥+−==−+−=

=−=

+=

AyxfyxfA

yxfyxfyxfA

yxfyxAfyxf

yxfyxfyxf

H

L

LHB

HL

The „high boost” filter

���

���

−−−−−−−−−

=1111191111

AhHBA=?

Page 20: Image filtering in spatial domain

: � ( '( : � ( '�

8 � � � � � �� �� �

High boost filter - example

Page 21: Image filtering in spatial domain

In order to keep the average value of the imageadd 1 do the centre element of the Laplace mask

���

���

−=170670170670332670170670170

2

...

...

...

h'

A modified Laplace filter

���

���

−=170670170670333670170670170

2

...

...

...

h

Page 22: Image filtering in spatial domain

���

���

−−−

−=

010151

010

3'h

���

���

−−−−−−−−

=111191111

4'h

Other high-pass filters

Page 23: Image filtering in spatial domain

� � � � � � �� � �� 5 �� � � � � � � �� � ��

%MATLABout_image = filter2(filter_mask, in_image);

High-pass filters

Page 24: Image filtering in spatial domain

Nonlinear filters

NO

The filtered image is defined by anon-linear function of the source image

Can we compute spectralcharacteristics for nonlinear filters?

Because transfer characteristics of nonlinearfilters depend on image content itself!

Page 25: Image filtering in spatial domain

Median filter (order statistic filter)

� � � � � � � m � � �� � � � � �� � � �� �� �

�� � � � �� � �� �� � � ����� ��� � � �� � �� �� �

� � �� � � � �� � � � �� �� � � �� � �� �� ��

� � m � � � � � � �� �� � � �� � � � 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

Page 26: Image filtering in spatial domain

��� � � ��� � ���� � �� � � � �� � , ��� � �+�� � �∈∈∈∈�.��� � �

Median filtering the image

� � � � � � �� � �� � � � �� � � �� � �� �

; �� � � � ���� � � � � � � � �� �

�� � � � � ��� � �� � � � ��� �

Page 27: Image filtering in spatial domain

Demo – median filter

Source image distorted by „salt and pepper noise”

Enhanced image usingthe median filter (3x3)”

%MATLABout_image = medfilt2(in_image, [m n]);

Page 28: Image filtering in spatial domain

Median filter

Median filter:

1. Excellent in reducing impulsive noise (od sizesmaller 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 orsmaller than the values of the input image(no rescaling)

4. Large computing cost involved

Page 29: Image filtering in spatial domain

Median filter

median average

[1 x 3] 1/3*[1 1 1]

Page 30: Image filtering in spatial domain

MATLAB Demo – median filter