Image filtering in spatial domain
Transcript of Image filtering in spatial domain
Image filtering
In Fourier domain In spatial domain
Linear filters Non-linear filters
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)
Filter definition in spatial domain
IF{H(u,v)}=h(x,y)
� �� �� �� � �� � �� � � F(�(x,y)) = �(x,y) � H(x,y)
���
� ��
� � � � � �
�(x,y) �
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 !
��� � � ��� � ���� � �� ��� � �� � ��� � ���� � �
�
Computing the filtered image
� � � � � � �� � �� � � � �� � � �� � �� �
���� � �
�
Boundary effects
� � � � � � �� � �� � � � �� � � �� � �� �
��� � �
�
� � � � � � � � � � � � � � � � � � � ! � � � � � ��� � �� � � �
� � � � � �� � � � � ��� �� �� � � � �� � �� �� � � � �" � � #$ ��� #$ �
Boundary effects – 3x3 mask
� ��� � � � � %&'' #( &'' #( )� � * � �� +
, � �" � $ - �� � � �" � � � ��� � � � � .
��� � � � � %#� �" � $ ''� �" � $ #� �" � $ ''� �" � $ )� � �� �� �� � +
'''
�� � ��� ( �� #$ � � �� � /�� ( �� #$ � �
* � ���
�%� /)�� &+
�� � � �� #� �" � $ �� � �" � $ � � �� � �� #� �" � $ �� � �" � $ � �
�%� /)�� �%� /)0 �%�0 � /0 )� �%�0 � /0 )+
� � � +
'''1 � � �� � �� � � �%� /)222
Image filtering – the algorithm
Low pass filter
���
�
�
���
�
�
=111111111
91
1h
������
�
�
������
�
�
=
1111111111111111111111111
251
2h
3 � � � � � � � � � � � � � � � 4 � � � �" � �
Frequency characteristics of low pass filters
�� � � �� � � � � �� � ���� � � �
H=freqz(h,m,n)
Low-pass filtering the image
5 � � � � � �� � ��
� �� � � � �
���� � � �
Gaussian filter
20
22 )(
),( d
yx
eyxh
+π−
=
�
����������������������
��������������������
���������������
���
�
�
���
�
�
=01130.
h
Nvud
evuH)( 222
0
),(+π−
=
���
�
�
���
�
�
=121242121
h
Image filtering using the Gaussian filter
� � � � � � �� � �� �� �� � � � �� � ��
Image low-pass filters - examples
6� � �� � �� �� � �� � * � ���
7 � � � � �� � � �� � �& &'&( �8 � ! � � � � �� �� � ���
� � ��� � ! � � �� �� �� � 9&� � &7 � � � � �� � �� �� � ���
�� � � � � �� ��
� � �� �
� ! #� � � � �� �� � � ��
7 � � � � �� � �� �� � � �� � � ��� � ! � � �� �� �� � 9&� �&
Image low-pass filters - examples
6� � �� � �� �� � �� � * � ���
7 � � � � �� � � � �� � �& &'&( �
Image low-pass filters - examples
6� � �� � �� �� � �� � * � ���
7 � � � � �� � � � �� � �& &'&&$ �8 � ! � � � � �� �� � ���
� � ��� � ! � � �� �� �� � 9&� � &7 � � � � �� � �� �� � ���
High-pass filters (derivative filters)
���
�
�
���
�
�
−−−−−−−−
=111181111
1h
���
�
�
���
�
�
−=170670170670333670170670170
2
...
...
...
h
� � � � �� �
High-pass filtering the image
mask h1 mask h2
1 ),,(),()1(
),(),(),()1(
),(),(),(
),(),(),(
≥+−==−+−=
=−=
+=
AyxfyxfA
yxfyxfyxfA
yxfyxAfyxf
yxfyxfyxf
H
L
LHB
HL
The „high boost” filter
���
�
�
���
�
�
−−−−−−−−−
=1111191111
AhHBA=?
: � ( '( : � ( '�
8 � � � � � �� �� �
High boost filter - example
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
���
�
�
���
�
�
−−−
−=
010151
010
3'h
���
�
�
���
�
�
−−−−−−−−
=111191111
4'h
Other high-pass filters
� � � � � � �� � �� 5 �� � � � � � � �� � ��
%MATLABout_image = filter2(filter_mask, in_image);
High-pass filters
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!
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
��� � � ��� � ���� � �� � � � �� � , ��� � �+�� � �∈∈∈∈�.��� � �
Median filtering the image
� � � � � � �� � �� � � � �� � � �� � �� �
�
; �� � � � ���� � � � � � � � �� �
�� � � � � ��� � �� � � � ��� �
Demo – median filter
Source image distorted by „salt and pepper noise”
Enhanced image usingthe median filter (3x3)”
%MATLABout_image = medfilt2(in_image, [m n]);
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
Median filter
median average
[1 x 3] 1/3*[1 1 1]
MATLAB Demo – median filter