Professional Documents
Culture Documents
K L University
Department of Electronics and Communication Engineering
Course Code: 15EC4110
Contents
1 Experiment 1 5
1.1 Histogram processing . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1.1 Normalized histograms . . . . . . . . . . . . . . . . . . . . 5
1.1.2 Matlab Function . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Matlab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Application 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Experimental Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Experiment 2 11
2.1 Histogram Equalization . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.1 Continuous Case . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.2 Discrete case (quantities): . . . . . . . . . . . . . . . . . . 12
2.2 Matlab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Application 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 Experimental Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 19
3 Experiment 3 20
3.1 Filtering in the spatial domain (Spatial Filtering) . . . . . . . . . 20
3.1.1 Linear Spatial Filtering . . . . . . . . . . . . . . . . . . . 21
3.1.2 Nonlinear Spatial Filtering . . . . . . . . . . . . . . . . . 21
3.2 Matlab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Application 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4 Experimental Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 27
1
4 Experiment 4 28
4.1 Frequency Domain Filtering . . . . . . . . . . . . . . . . . . . . . 28
4.1.1 Low-pass filtering . . . . . . . . . . . . . . . . . . . . . . . 29
4.1.2 High-pass filtering . . . . . . . . . . . . . . . . . . . . . . 30
4.2 Matlab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.3 Experimental Tasks . . . . . . . . . . . . . . . . . . . . . . . . . 36
2
This set of experiments is based on MATLAB. These experiments will allow
any instructor to cover experiments in most of the topics treated in a regular
image processing course to be completed successfully.
Introduction
Motivation for a digital image processing course arises mainly from two areas
of applications, namely, a) an increase in the pictorial information available for
human interpretation, and b) image processing for automatic and autonomous
machine control. This is because vision is the most important human sense in
terms of the amount of information it conveys and because of a good visualiza-
tion is very important for the correct information converged in an image.
Many image processing circuits require dedicated software to perform their
tasks. These packages usually are highly priced and are not easily modified
by the final user. The basis for the image processing is MATLAB software
package now available almost anywhere for other uses and that is used as the
engine for the image processing experiments. The software written for the image
processing experiments is available from the users at no cost to interested users
and instructors.
Image processing applications include many topics, among which we can
mention remote sensing, ultrasound images, meteorology, astronomy, inspection,
radar, seismology, radiology, autonomous navigation, recognition, etc.
3
Application 1: Develop an automatic thresholding algorithm such as (Otsus)
for defect identification.
Exp 2: Histogram Processing for Contrast Enhancement. This laboratory
experiment provides for histogram equalization and matching for contrast en-
hancement. The user must express these algorithms on 10 sets of different
contrast images and measure the performance of the algorithms on each image
set. This experiment illustrates the relationship among the intensities (gray
levels) of an image and its histogram. It shows how to improve the image by
equalizing the histogram.
Application 2: Color Image Enhancement Using Histogram Equalization
Method without Changing Hue and Saturation
Exp 3: Spatial Filtering. Linear and Non-linear spatial filtering. Learn the
concepts of designing spatial filters in time domain. Use different kinds of spatial
filters to improve the quality of images. Measure the quality of improved images
against the original images.
Application 3: Fingerprint Image Enhancement using Filtering Techniques
Exp 4: Frequency Domain Filtering: Use low pass and high pass filtering
kernels to sharpen an image with Two-dimensional Fourier transform. The
purpose of this experiment is to provide an understanding of the harmonic
content of an image using the discrete Fourier transform (DFT). This experiment
is designed so the student learns the concept of masking with the DFT.
Exp 5: Morphological operations I. This experiment is intended so students
can appreciate the effect of morphological operations using a small structuring
element on simple binary images. The operations that can be performed are
erosion, dilation, opening, closing, open-close, close-open. how morphological
functions change images by applying consecutive erosion and dilation operations.
Exp 6: Linear filtering using 2D convolution. After completing this exper-
iment every student should understand the concepts of filtering using linear
convolution.
Exp 7: Edge detection. Use at least 5 edge detectors. This experiment
enables students to understand the concept of edge detectors and the operation
in noisy images.
Exp 8: Image Restoration. Adding Noise. Types of Noise. This experiment
enables students understanding spatial noise filters in restoration.
Exp 9: Image Registration. Geometric spatial transformations on images to
handle miss-aligned images. This experiment enables student to apply transfor-
mation on images captured in the wild using unconstrained capture methods.
Exp 10: Video background subtraction with analysis. This experiment en-
ables student to understand the dynamics of video processing. Motion segmen-
tation is a critical task in surveillance video object detection and estimation.
4
1 Experiment 1
Point–to–point transformation. This laboratory experiment provides for
thresholding an image and the evaluation of its histogram. The user can choose
a threshold level to see the image showing only the pixels at that threshold.
h(rk ) = nk
Where
• rk is the k th gray level
• nk is the number of pixels in the image having gray level rk
h(rk ) nk
P (rk ) = = , f or k = 1, 2, ..., L
n n
n total number of pixels
Thus P (rk ) gives an estimate of the probability of occurrence of gray level
rk . Note that the sum of all components of a normalized histogram is equal to
1.
1.1.2 Matlab Function
h= imhist(f,b)
5
1.2 Matlab Code
1 clc ;
2 clear all ;
3 close all ;
4
5 I=imread ( ’ cameraman . t i f ’ ) ;
6 I=i m r e s i z e ( I , [ 2 5 6 2 5 6 ] ) ;
7 f i g u r e , imshow ( I ) ;
8 %% t h e s i m p l e s t way t o p l o t i t s h i s t o g r a m i s t o u s e
i m h i s t with no output s p e c i f i e d
9
10 figure , imhist ( I ) ;
11
12 %% Histograms o f t e n a r e p l o t t e d u s i n g bar g r a p h s
13
14 h=i m h i s t ( I ) ;
15 h1=h ( 1 : 1 0 : 2 5 6 ) ;
16 horz =1:10:256;
17 f i g u r e , bar ( horz , h1 ) ;
18 a x i s ( [ 0 255 0 2 5 0 0 ] )
19 s e t ( gca , ’ x t i c k ’ , 0 : 5 0 : 2 5 5 )
20 s e t ( gca , ’ y t i c k ’ , 0 : 5 0 0 : 2 5 0 0 )
21 %% Stem graph
22
23 h=i m h i s t ( I ) ;
24 h1=h ( 1 : 1 0 : 2 5 6 ) ;
25 horz =1:10:256;
26 f i g u r e , stem ( horz , h1 , ’ f i l l ’ ) ;
27 a x i s ( [ 0 255 0 2 5 0 0 ] )
28 s e t ( gca , ’ x t i c k ’ , 0 : 5 0 : 2 5 5 )
29 s e t ( gca , ’ y t i c k ’ , 0 : 5 0 0 : 2 5 0 0 )
30
31 %% p l o t graph
32
33 h=i m h i s t ( I ) ;
34 figure , plot (h) ;
35 a x i s ( [ 0 255 0 2 5 0 0 ] )
36 s e t ( gca , ’ x t i c k ’ , 0 : 5 0 : 2 5 5 )
37 s e t ( gca , ’ y t i c k ’ , 0 : 5 0 0 : 2 5 0 0 )
6
1.2.1 Results
(e) plot
7
1.3 Application 1
Develop an automatic thresholding algorithm for defect identification
1 clc ;
2 clear all ;
3 close all ;
4
5 I 1 = imread ( ’ b l o o d . png ’ ) ;
6 % f a s t e s t h i s t o g r a m computation .
7 I = im2uint8 ( I1 ( : ) ) ;
8
35 i=i +1;
36 T( i )=round ( (MAT+MBT) / 2 ) ;
37 T h r e s h o l d=T( i ) ;
38 end
8
39
40 % Normalize t h e t h r e s h o l d t o t h e r a n g e [ i , 1 ] .
41 l e v e l = ( T h r e s h o l d − 1 ) / (N( end ) − 1 ) ;
42
43 BW = im2bw ( I1 , l e v e l ) ;
44 imshow (BW) ;
9
1.3.1 Results
10
2 Experiment 2
Histogram Processing for Contrast Enhancement. This laboratory experi-
ment provides for histogram equalization and matching for contrast enhance-
ment. The user must express these algorithms on 10 sets of different contrast
images and measure the performance of the algorithms on each image set. This
experiment illustrates the relationship among the intensities (gray levels) of an
image and its histogram. It shows how to improve the image by equalizing the
histogram.
Let Pr (r) – probability density function (PDF) of the intensity levels. The
following transformation on the input levels to obtain output levels, S :
Z r
S = T (r) = Pr (w)dw
0
1 0≤S≤1
PS (S) =
0 Otherwise
* Image, whose intensity levels are equally likely, and it cover the entire
range [0 ,1].
11
2.1.2 Discrete case (quantities):
The equalization transformation becomes:
Xk Xk nj
Sk = T (rk ) = Pr (rj ) = , f or k = 1, 2, ..., L
j=1 j=1 n
Sk –Intensity value of the output image corresponding to value rk in the input
image.
12
2.2 Matlab Code
1 clc ;
2 close all ;
3 clear all ;
4
8 [ rows c o l s ]= s i z e (F) ;
9 G=F ;
10
11 %% Histogram a r r a y
12 myhist=z e r o s ( 2 5 6 , 1 ) ;
13 f o r k=0 : 255
14 myhist ( k+1)=numel ( f i n d (F==k ) ) ; %number o f e l e m e n t s where
F has gray l e v e l e q u a l t o ’ k ’
15 end
16 %End o f Histogram a r r a y
17
18
19 %% C a l c u l a t e c d f
20 c d f=z e r o s ( 2 5 6 , 1 ) ;
21 c d f ( 1 )=myhist ( 1 ) ;
22 f o r k=2 : 256
23 c d f ( k )=c d f ( k−1)+myhist ( k ) ;
24 end
25 %End o f C a l c u l a t e c d f
26
27 %% Find E q u a l i z e d h i s t o g r a m a r r a y
28 cumprob=c d f / ( rows . ∗ c o l s ) ;
29 e q u a l i z e d h i s t=f l o o r ( ( cumprob ) . ∗ 2 5 5 ) ;
30
31 f o r i =1 : c o l s
32 f o r j =1 : rows
33 f o r m = 0 : 255
34 i f (F( i , j )==m)
35 G( i , j )=e q u a l i z e d h i s t (m+1) ;
36 end
37 end
38 end
39 end
40
13
41 %% E q u a l i z e d Histogram a r r a y
42 myeqhist=z e r o s ( 2 5 6 , 1 ) ;
43 f o r k=0 : 255
44 myeqhist ( k+1)=numel ( f i n d (G==k ) ) ;
45 end
46 %End o f E q u a l i z e d Histogram a r r a y
47
48 %% p l o t s and f i g u r e s
49 figure (1) ;
50 subplot (2 ,1 ,1) ;
51 imshow (F) ;
52 t i t l e ( ’ O r i g i n a l Image ’ ) ;
53 subplot (2 ,1 ,2) ;
54 bar ( myhist ) ;
55 t i t l e ( ’ Histogram o f O r i g i n a l Image ’ ) ;
56
57 figure (2) ;
58 subplot (2 ,1 ,1) ;
59 imshow (G) ;
60 t i t l e ( ’ Histogram E q u a l i z e d Image ’ ) ;
61 subplot (2 ,1 ,2) ;
62 bar ( myeqhist ) ;
63 t i t l e ( ’ E q u a l i z e d Histogram o f Image ’ ) ;
64 %end p l o t s and f i g u r e s
14
2.2.1 Results
15
2.3 Application 2
Color Image Enhancement Using Histogram Equalization Method without
Changing Hue and Saturation
1 clc ;
2 clear all ;
3 close all ;
4 %% Improving C o l o r e d Low c o n t r a s t Image u s i n g HE
5 I = imread ( ’LC6 . j p g ’ ) ;
6 I = imresize ( I ,[512 512]) ;
7 imshow ( I )
8 HSv = rgb2hsv ( I ) ;
9 % f i g u r e , imshow (HSv)
10 H = HSv ( : , : , 1 ) ;
11 S = HSv ( : , : , 2 ) ;
12 V = HSv ( : , : , 3 ) ;
13
14 Vc = V∗ 3 . 4 ;
15 HSV = c a t ( 3 ,H, S , Vc ) ;
16 RGB = hsv2rgb (HSV) ;
17 f i g u r e , imshow (RGB) ;
18
19 %% RGB 2 HSI
20 A = I;
21 I=d o u b l e (A) / 2 5 5 ;
22
23 R=I ( : , : , 1 ) ;
24 G=I ( : , : , 2 ) ;
25 B=I ( : , : , 3 ) ;
26
27 %Hue
28 numi =1/2∗((R−G) +(R−B) ) ;
29 denom=((R−G) . ˆ 2 + ( (R−B) . ∗ (G−B) ) ) . ˆ 0 . 5 ;
30
37 %Normalize t o t h e r a n g e [ 0 1 ]
38 H=H/ 3 6 0 ;
16
39
40 %S a t u r a t i o n
41 S=1− ( 3 . / ( sum ( I , 3 ) +0.000001) ) . ∗ min ( I , [ ] , 3 ) ;
42
43 %I n t e n s i t y
44 I=sum ( I , 3 ) . / 3 ;
45 I = I ∗4.4;
46
47 %HSI
48 HSI=z e r o s ( s i z e (A) ) ;
49 HSI ( : , : , 1 )=H;
50 HSI ( : , : , 2 )=S ;
51 HSI ( : , : , 3 )=I ;
52
53 %% HSI t o RGB
54 H1=HSI ( : , : , 1 ) ;
55 S1=HSI ( : , : , 2 ) ;
56 I 1=HSI ( : , : , 3 ) ;
57
58 %M u l t i p l y Hue by 360 t o r e p r e s e n t i n t h e r a n g e [ 0 3 6 0 ]
59 H1=H1 ∗ 3 6 0 ;
60
67 %RG S e c t o r (0<=H<120)
68 %When H i s i n t h e above s e c t o r , t h e RGB components
equations are
69
74 %GB S e c t o r (120<=H<240)
75 %When H i s i n t h e above s e c t o r , t h e RGB components
equations are
76 %S u b t r a c t 120 from Hue
77 H2=H1−120;
78
17
H1<240) . ∗ c o s d (H2(H1>=120&H1<240) ) ) . / c o s d (60−H2(H1
>=120&H1<240) ) ) ) ;
81 B1 (H1>=120&H1<240) =3.∗ I 1 (H1>=120&H1<240)−(R1(H1>=120&H1
<240)+G1(H1>=120&H1<240) ) ;
82
83 %BR S e c t o r (240<=H<=360)
84 %When H i s i n t h e above s e c t o r , t h e RGB components
equations are
85 %S u b t r a c t 240 from Hue
86
87 H2=H1−240;
88
98 %R e p r e s e n t t h e image i n t h e r a n g e [ 0 2 5 5 ]
99 RGB1=i m 2 u i n t 8 (RGB1) ;
100 f i g u r e , imshow (RGB1) ;
18
2.3.1 Results
(b) Enhanced image using HSV (c) Enhanced image using HSI
method method
19
3 Experiment 3
Spatial Filtering. Linear and Non-linear spatial filtering. Learn the concepts
of designing spatial filters in time domain. Use different kinds of spatial filters to
improve the quality of images. Measure the quality of improved images against
the original images.
20
3.1.1 Linear Spatial Filtering
The process consists of moving the filter mask from pixel to pixel in an
image. At each pixel (x, y), the response is given by a sum of products of the
filter coefficients and the corresponding image pixels in the area spanned by the
filter mask. For the 3 × 3 mask shown in the previous figure, the result (or
response), R, of linear filtering is:
a
X b
X
g(x, y) = w(s, t)f (x + s, y + t)
s=−a t=−b
21
3.2 Matlab Code
1 clc ;
2 clear all ;
3 close all ;
4
5 %Read an Image
6 Img = imread ( ’LF . j p g ’ ) ;
7 Img=r g b 2 g r a y ( Img ) ;
8 A = i m n o i s e ( Img , ’ Gaussian ’ , 0 . 0 4 , 0 . 0 0 3 ) ;
9 %A =i m n o i s e ( Img , ’ s a l t & pepper ’ , 0 . 0 1 ) ;
10 %
11 %Image with n o i s e
12 f i g u r e , imshow (A) ;
13
14 %% L i n e a r f i l t e r i n g
15
16 %% H = f s p e c i a l ( ’ g a u s s i a n ’ , h s i z e , sigma ) %r e t u r n s a
r o t a t i o n a l l y symmetric Gaussian l o w p a s s f i l t e r o f s i z e
h s i z e with s t a n d a r d d e v i a t i o n sigma ( p o s i t i v e ) .
17 H = f s p e c i a l ( ’ Gaussian ’ , [ 9 9 ] , 1 . 7 6 ) ;
18
19 %% H = f s p e c i a l ( ’ average ’ , h s i z e ) % r e t u r n s an a v e r a g i n g
f i l t e r h of size hsize .
20 H = f s p e c i a l ( ’ average ’ , [ 3 3 ] ) ;
21
22 %% H = f s p e c i a l ( ’ d i s k ’ , r a d i u s ) r e t u r n s a c i r c u l a r
a v e r a g i n g f i l t e r ( p i l l b o x ) w i t h i n t h e s q u a r e matrix o f
s i z e 2∗ r a d i u s +1.
23 H = f s p e c i a l ( ’ disk ’ ,5) ;
24
25 %% H = f s p e c i a l ( ’ motion ’ , l e n , t h e t a ) r e t u r n s a f i l t e r t o
approximate , once c o n v o l v e d with an image , t h e l i n e a r
motion o f a camera by l e n p i x e l s , with an a n g l e o f
t h e t a d e g r e e s i n a c o u n t e r c l o c k w i s e d i r e c t i o n . The
f i l t e r becomes a v e c t o r f o r h o r i z o n t a l and v e r t i c a l
motions .
26 H = f s p e c i a l ( ’ motion ’ , 9 , 0 ) ;
27
28 %f i l t e r s : ’ ave rage ’ , ’ d i s k ’ , ’ g a u s s i a n ’ , ’ l a p l a c i a n ’ , ’ l o g ’ ’
motion ’ , ’ p r e w i t t ’ , ’ s o b e l ’ , ’ unsharp ’
29 SF = i m f i l t e r (A,H) ;
30 f i g u r e , imshow ( SF ) ;
22
31
32 %% N o n l i n e a r f i l t e r i n g
33 % B = medfilt2 ( , padopt ) c o n t r o l s how m e d f i l t 2 pads t h e
matrix b o u n d a r i e s .
34
35 H = m e d f i l t 2 (A, ’ symmetric ’ ) ;
36 f i g u r e , imshow (H) ;
23
3.2.1 Results
24
3.3 Application 3
Fingerprint Image Enhancement using Filtering Techniques
1 clc ;
2 clear all ;
3 close all ;
4
5 %Read an Image
6 Img = imread ( ’ FPI1 . png ’ ) ;
7 % Img=r g b 2 g r a y ( Img ) ;
8 % A = i m n o i s e ( Img , ’ Gaussian ’ , 0 . 0 4 , 0 . 0 0 3 ) ;
9 %A =i m n o i s e ( Img , ’ s a l t & pepper ’ , 0 . 0 1 ) ;
10 Img = i m r e s i z e ( Img , [ 2 5 6 2 5 6 ] ) ;
11 %Image with n o i s e
12 f i g u r e , imshow ( Img ) ;
13
14 %% H = f s p e c i a l ( ’ g a u s s i a n ’ , h s i z e , sigma ) %r e t u r n s a
r o t a t i o n a l l y symmetric Gaussian l o w p a s s f i l t e r o f s i z e
h s i z e with s t a n d a r d d e v i a t i o n sigma ( p o s i t i v e ) .
15 Hg = f s p e c i a l ( ’ Gaussian ’ , [ 5 5 ] , 5 0 . 5 ) ;
16
17 %f i l t e r s : ’ ave rage ’ , ’ d i s k ’ , ’ g a u s s i a n ’ , ’ l a p l a c i a n ’ , ’ l o g ’ ’
motion ’ , ’ p r e w i t t ’ , ’ s o b e l ’ , ’ unsharp ’
18 PSF = f s p e c i a l ( ’ g a u s s i a n ’ , 5 , 2 ) ;
19 PSF = Hg ;
20 UNDERPSF = o n e s ( s i z e (PSF) −4) ;
21 INITPSF = padarray (UNDERPSF, [ 2 2 ] , ’ r e p l i c a t e ’ , ’ both ’ ) ;
22 SF = i m f i l t e r ( Img , Hg) ;
23 % SF = h i s t e q ( SF ) ;
24 SF1 = edge ( Img , ’ s o b e l ’ , 0 . 2 5 ) ;
25 WEIGHT = SF1 ;
26 se = s t r e l ( ’ l i n e ’ ,3 ,0) ;
27 WEIGHT = 1−d o u b l e ( i m d i l a t e (WEIGHT, s e ) ) ;
28 WEIGHT( [ 1 : 3 end − ( 0 : 2 ) ] , : ) = 0 ;
29 WEIGHT( : , [ 1 : 3 end − ( 0 : 2 ) ] ) = 0 ;
30 f i g u r e ; imshow (WEIGHT) ; t i t l e ( ’ Weight a r r a y ’ ) ;
31 [ J , P ] = d e c o n v b l i n d ( Img , INITPSF , 2 0 0 , [ ] ,WEIGHT) ;
32 f i g u r e ; imshow ( J ) ; t i t l e ( ’ F Inge r P r i n t Enhnaced Image ’ ) ;
33 SF3 = edge ( J , ’ canny ’ , 0 . 0 2 ) ;
34 f i g u r e , imshow ( ˜ SF3 ) ;
35 SF2 = edge ( Img , ’ canny ’ , 0 . 0 2 ) ;
36 f i g u r e , imshow ( ˜ SF2 )
25
3.3.1 Results
26
3.4 Experimental Tasks
Task 1: Test the application for different set of ‘10 images.
Task 2: Give a performance report on the tests performed with a perfor-
mance parameter.
Task 3: Write a report.
27
4 Experiment 4
Frequency Domain Filtering: Use low pass and high pass filtering kernels
to sharpen an image with Two-dimensional Fourier transform. The purpose of
this experiment is to provide an understanding of the harmonic content of an
image using the discrete Fourier transform (DFT). This experiment is designed
so the student learns the concept of masking with the DFT.
28
Figure 8: block diagram
The filter is called ideal because all the frequencies inside the circle of radius
D are passed with no attenuation, whereas all frequencies outside this circle are
completely attenuated.
1
/2
D(u, v) = (u2 + v 2 )
The drawback of this filter function is a ringing effect that occurs along the
edges of the filtered spatial domain image.
29
4.1.1.2 Butterworth low-pass filter
The Butterworth low-pass filter is an approximation to the ideal filter with-
out the step discontinuity. The transfer function of the Butterworth low-pass
filter of order n and with cut-off frequency locus at a distance D from the origin
is defined by the relation:
1
H(u, v) = 2n
1 + [D(u, v)/D0 ]
Unlike the ideal low-pass filter, the Butterworth filter does not have a sharp
discontinuity that establishes a clear cut-off between passed and filtered fre-
quencies.
4.1.1.3 Gaussian low-pass filter
Gaussian low pass filter have smooth transition between pass band and stop
band. It does not introduce any ringing in the output image. The transfer
function of GLPF is given by:
2
(u,v)/2D02
H(u, v) = e−D
We only consider zero-phase-shift filters that are radially symmetric and can
be completely specified by cross section extending as a function of distance from
the origin at center. The three high-pass filters that we will consider are:
(a) Ideal high-pass filter
30
4.1.2.1 Ideal high-pass filter
The ideal high-pass filter is one which satisfies the relation:
0, if D(u, v) ≤ D0
H(u, v) =
1, if D(u, v) > D0
This filter completely attenuates all frequencies inside a circle of radius D0 while
passing, without attenuation, all frequencies outside the circle.
4.1.2.2 Butterworth high-pass filter
As in the case of the Butterworth low-pass filter, common practice is to
select the cut-off frequency locus at points for which H(u, v) is down to 1 /√2 of
its maximum value.
4.1.2.3 Gaussian high-pass filter
Gaussian low pass filter have smooth transition between pass band and stop
band. The parameter D0 is a measure of spread of the gaussian curve. Larger
the value D0 , larger is the cut off frequency. The transfer function of GLPF is
given by:
2
(u,v)/2D02
H(u, v) = 1 − e−D
Here, D0 = cut off frequency, D(u, v) is the distance from origin of fourier
transform.
31
4.2 Matlab Code
1 clc ;
2 clear all ;
3 close all ;
4
5 I=imread ( ’ FF3 . j p g ’ ) ;
6 %I=i m r e s i z e ( I , [ 5 1 2 5 1 2 ] ) ;
7 I=r g b 2 g r a y ( I ) ;
8
9 PQ=s i z e ( I ) ;
10 F=f f t 2 ( I ) ; % Ft o f i n p u t
11 % c r e a t e i d e a l LPF & BLPF
12 M=PQ( 1 ) ;
13 N=PQ( 2 ) ;
14 D0=30;
15 n=2;
16 u =0:(M−1) ;
17 v =0:(N−1) ;
18 % compute t h e i n d i c e s f o r u s e i n meshgrid
19 i d x=f i n d ( u>M/ 2 ) ;
20 u ( i d x )=u ( i d x )−M;
21 i d y=f i n d ( v>N/ 2 ) ;
22 v ( i d y )=v ( i d y )−N;
23 % compute t h e meshgrid a r r a y s
24 [ V,U]= meshgrid ( v , u ) ;
25 % compute t h e d i s t a n c e D(U,V)
26 D=s q r t (U.ˆ2+V. ˆ 2 ) ;
27
28 %% I d e a l Low p a s s f i l t e r
29 H=d o u b l e (D<=D0) ; % low p a s s f i l t e r
30 f i g u r e , s u r f l ( f f t s h i f t (H) ) , s h a d i n g i n t e r p , colormap ( gray ) ;
%p l o t f i l t e r
31 f i g u r e , imshow ( f f t s h i f t ( l o g (H) +1) ) ; %p l o t f i l t e r a s image
32 %f i l t e r m u l t i f i c a t i o n
33 f 1=r e a l ( i f f t 2 (H. ∗ F) ) ; %m u l t i p l i c a t i o n , IDFT , Real p a r t
34 %D i s p l a y images
35 imshow ( I ) ;
36 f i g u r e , imshow ( f f t s h i f t ( l o g (F) +1) , [ ] ) ;%d i s p l a y i n p u t and
i t s DFT
37 f i g u r e , imshow ( f 1 /max( f 1 ( : ) ) ) ; %d i s p l a y output
38 %
39 %% Butterworth Low p a s s f i l t e r
32
40 %
41 H=1./(1+D. / D0) . ˆ ( 2 ∗ n ) ;
42 f i g u r e , s u r f l ( f f t s h i f t (H) ) , s h a d i n g i n t e r p , colormap ( gray ) ;
%p l o t f i l t e r
43 f i g u r e , imshow ( f f t s h i f t ( l o g (H) +1) ) ; %p l o t f i l t e r a s image
44 % f i l t e r i m p l e m e n t a t i o n i n f r e q u e n c y domain
45 f 1=r e a l ( i f f t 2 (H. ∗ F) ) ; % f i l t e r m u l t i p l i c a t i o n , IDFT , Real
part
46 f i g u r e , imshow ( f1 , [ ] ) ; %d i s p l a y output
47 %
48 %% Gaussian Low p a s s f i l t e r
49 %
50 H=exp (−(D. ˆ 2 ) . / ( 2 ∗ ( D0ˆ 2 ) ) ) ; % Gaussian LPF
51 f i g u r e , s u r f l ( f f t s h i f t (H) ) , s h a d i n g i n t e r p , colormap ( gray ) ;
%p l o t f i l t e r
52 f i g u r e , imshow ( f f t s h i f t ( l o g (H) +1) ) ; %p l o t f i l t e r a s image
53 % f i l t e r i m p l e m e n t a t i o n i n f r e q u e n c y domain
54 f 1=r e a l ( i f f t 2 (H. ∗ F) ) ; % f i l t e r m u l t i p l i c a t i o n , IDFT , Real
part
55 f i g u r e , imshow ( f1 , [ ] ) ; %d i s p l a y output
56
57 %% I d e a l High p a s s f i l t e r
58 H=d o u b l e (D<=D0) ; % low p a s s f i l t e r
59 H1=1−H;
60 f i g u r e , s u r f l ( f f t s h i f t (H1) ) , s h a d i n g i n t e r p , colormap ( gray )
; %p l o t f i l t e r
61 f i g u r e , imshow ( f f t s h i f t ( l o g (H1) +1) ) ; %p l o t f i l t e r a s
image
62 %f i l t e r m u l t i f i c a t i o n
63 f 1=r e a l ( i f f t 2 (H1 . ∗ F) ) ; %m u l t i p l i c a t i o n , IDFT , Real p a r t
64 %D i s p l a y images
65 imshow ( I ) ;
66 f i g u r e , imshow ( f f t s h i f t ( l o g (F) +1) , [ ] ) ;%d i s p l a y i n p u t and
i t s DFT
67 f i g u r e , imshow ( f 1 /max( f 1 ( : ) ) ) ; %d i s p l a y output
68
69 %% Butterworth High p a s s f i l t e r
70
71 H=1./(1+D. / D0) . ˆ ( 2 ∗ n ) ;
72 H1=1−H;
73 f i g u r e , s u r f l ( f f t s h i f t (H1) ) , s h a d i n g i n t e r p , colormap ( gray )
; %p l o t f i l t e r
74 f i g u r e , imshow ( f f t s h i f t ( l o g (H1) +1) ) ; %p l o t f i l t e r a s
image
75 % f i l t e r i m p l e m e n t a t i o n i n f r e q u e n c y domain
76 f 1=r e a l ( i f f t 2 (H1 . ∗ F) ) ; % f i l t e r m u l t i p l i c a t i o n , IDFT , Real
33
part
77 f i g u r e , imshow ( f1 , [ ] ) ; %d i s p l a y output
78 %
79 %% Gaussian High p a s s f i l t e r
80 %
81 H=exp (−(D. ˆ 2 ) . / ( 2 ∗ ( D0ˆ 2 ) ) ) ; % Gaussian LPF
82 H1=1−H;
83 f i g u r e , s u r f l ( f f t s h i f t (H1) ) , s h a d i n g i n t e r p , colormap ( gray )
; %p l o t f i l t e r
84 f i g u r e , imshow ( f f t s h i f t ( l o g (H1) +1) ) ; %p l o t f i l t e r a s
image
85 % f i l t e r i m p l e m e n t a t i o n i n f r e q u e n c y domain
86 f 1=r e a l ( i f f t 2 (H1 . ∗ F) ) ; % f i l t e r m u l t i p l i c a t i o n , IDFT , Real
part
87 f i g u r e , imshow ( f1 , [ ] ) ; %d i s p l a y output
34
4.2.1 Results
35
(a) Ideal high-pass filter (b) Butterworth high-pass filter
36