Scilab Manual For Image Processing by MR Gautam Pal Computer Engineering Tripura Institute of Technlogy
Scilab Manual For Image Processing by MR Gautam Pal Computer Engineering Tripura Institute of Technlogy
Scilab Manual For Image Processing by MR Gautam Pal Computer Engineering Tripura Institute of Technlogy
Image Processing
by Mr Gautam Pal
Computer Engineering
Tripura Institute of Technlogy1
Solutions provided by
Mr R.Senthilkumar- Assistant Professor
Electronics Engineering
Institute of Road and Transport Technology
2
operations and use them for i) Linear filtering ii) Non-linear
filtering 28
3
List of Experiments
4
List of Figures
3.1 Exp3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Exp3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.1 Exp4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Exp4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
8.1 Exp8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
11.1 Exp11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
14.1 Exp14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
15.1 Exp15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5
Experiment: 1
1 // Prog1 . Image A r i t h m e t i c − To l e a r n t o u s e
a r i t h m e t i c o p e r a t i o n s t o combine i m a g e s .
2 // S o f t w a r e v e r s i o n
3 //OS Windows7
4 // S c i l a b 5 . 4 . 1
5 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
6 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
7 clc ;
8 clear ;
9 close ;
10 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ cameraman . j p e g ’ ) ; // SIVP
toolbox
11 J = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
6
Gautam PAL Lab \ DIP Lab2 \ r i c e . png ’ ) ; // SIVP t o o l b o x
12 IMA = imadd (I , J ) ; // SIVP t o o l b o x
13 figure
14 ShowImage ( IMA , ’ Image A d d i t i o n ’ ) // IPD t o o l b o x
15 IMS = imabsdiff (I , J ) ; // SIVP t o o l b o x
16 figure
17 ShowImage ( IMS , ’ Image S u b t r a c t i o n ’ ) ; // IPD t o o l b o x
18 IMD = imdivide (I , J ) ; // SIVP t o o l b o x
19 IMD = imdivide ( IMD ,0.01) ; // SIVP t o o l b o x
20 figure
21 ShowImage ( uint8 ( IMD ) , ’ Image D i v i s i o n ’ ) ; // IPD t o o l b o x
22 IMM = immultiply (I , I ) ; // SIVP t o o l b o x
23 figure
24 ShowImage ( uint8 ( IMM ) , ’ Image M u l t i p l y ’ ) ; // IPD t o o l b o x
7
Experiment: 2
1 // Prog2 . D i s t a n c e and C o n n e c t i v i t y : To u n d e r s t a n d t h e
notion of connectivity
2 // and n e i g h b o r h o o d d e f i n e d f o r a p o i n t i n an image .
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
11 // [ 1 ] . E u c l i d e a n D i s t a n c e b e t w e e n i m a g e s and t h e i r
histograms
12 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
13 J = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
8
Gautam PAL Lab \ DIP Lab2 \ cameraman . j p e g ’ )
14 h_I = CreateHistogram ( I ) ; // IPD t o o l b o x
15 h_J = CreateHistogram ( J ) ; // IPD t o o l b o x
16 I = double ( I ) ;
17 J = double ( J ) ;
18 E_dist_Hist = sqrt ( sum (( h_I - h_J ) .^2) ) ; // E u c l i d e a n
D i s t a n c e b e t w e e n h i s t o g r a m s o f two i m a g e s
19 E_dist_images = sqrt ( sum (( I (:) -J (:) ) .^2) ) ; //
E u c l i d e a n D i s t a n c e b e t w e e n two i m a g e s
20 disp ( E_dist_images , ’ E u c l i d e a n D i s t a n c e b e t w e e n two
images ’ );
21 disp ( E_dist_Hist , ’ E u c l i d e a n D i s t a n c e b e t w e e n
h i s t o g r a m s o f two i m a g e s ’ )
22 // [ 2 ] . C o n n e c t i v i t y − 8 c o n n e c t e d t o t h e b a c k g r o u n d
23 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
gray2bin . s c i ’)
24 Ibin = gray2bin ( I ) ;
25 Jbin = gray2bin ( J ) ;
26 // c o n v e r s i o n o f g r a y image i n t o b i n a r y image
27 conn = [1 ,1 ,1;1 ,1 ,1;1 ,1 ,1]; //8− c o n n e c t i v i t y
28 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
numdims . s c i ’ )
29 num_dims = numdims ( I ) ;
30 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
padarray . s c i ’ )
31 B = padarray ( Ibin ) ;
32 global FILTER_ERODE ;
33 StructureElement = CreateStructureElement ( ’ s q u a r e ’ ,
3) ;
34 B_eroded = MorphologicalFilter (B , FILTER_ERODE ,
StructureElement . Data ) ; // IPD t o o l b o x
35 // n o t e : S t r u c t u r e E l e m e n t . Data and conn b o t h a r e same
values
36 // e x c e p t t h a t S t r u c t u r e E l e m e n t . Data i s b o o l e a n
e i t h e r true or f a l s e
37 p = B &~ B_eroded ;
38 [m , n ] = size ( p ) ;
39 for i = num_dims : m + num_dims -2
9
40 for j = num_dims : n + num_dims -2
41 pout (i -1 ,j -1) = p (i , j ) ;
42 end
43 end
44 figure
45 ShowImage ( uint8 ( I ) , ’ Gray Lenna Image ’ )
46 figure
47 ShowImage ( Ibin , ’ B i n a r y Lenna Image ’ )
48 figure
49 ShowImage ( pout , ’ 8 n e i g h b o u r h o o d c o n n e c t i v i y i n Lenna
Image ’ )
gray2bin.sci
numdims.sci
padarray.sci
10
Experiment: 3
11
Gautam PAL Lab \ DIP Lab2 \ m i s t y m o r n i n g . j p g ’ ) ;
12 I = imresize (I ,[300 ,300] , ’ b i c u b i c ’ ) ;
13 J = imresize (J ,[300 ,300] , ’ b i c u b i c ’ ) ;
14 K = imadd (I , J )
15 ShowColorImage (I , ’ Red Rose C o l o r Image ’ )
16 figure
17 ShowColorImage (J , ’ M i s t y Morning C o l o r Image ’ )
18 figure
19 ShowColorImage (K , ’ C o l o r I m a g e s a d d i t i o n r e s u l t image
’)
20 I_gray = rgb2gray ( I ) ;
21 J_gray = rgb2gray ( J ) ;
22 figure
23 ShowImage ( I_gray , ’ Red Rose Gray Image ’ )
24 figure
25 ShowImage ( J_gray , ’ M i s t y Morning Gray Image ’ )
26 Imean = mean2 ( I_gray ) ;
27 Jmean = mean2 ( J_gray ) ;
28 Ithreshold = double ( Imean ) / double ( max ( I_gray (:) ) ) ;
29 Jthreshold = double ( Jmean ) / double ( max ( J_gray (:) ) ) ;
30 I_bw = im2bw (I , Ithreshold ) ;
31 J_bw = im2bw (J , Jthreshold ) ;
32 figure
33 ShowImage ( I_bw , ’ Red Rose B i n a r y Image ’ )
34 figure
35 ShowImage ( J_bw , ’ M i s t y Morning B i n a r y Image ’ )
12
Figure 3.1: Exp3
13
Figure 3.2: Exp3
14
Experiment: 4
15
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
12 K = imabsdiff (I , J ) ;
13 ShowImage (I , ’ Cameraman Image ’ )
14 figure
15 ShowImage (J , ’ Lenna Image ’ )
16 figure
17 ShowImage (K , ’ A b s o l u t e D i f f e r e n c e Between cameraman
and Lenna Image ’ )
18 L = imcomplement ( K ) ;
19 figure
20 ShowImage (L , ’ Complement o f d i f f e r e n c e Image K ’ )
21 rect = [20 ,30 ,200 ,200];
22 I_subimage = imcrop (I , rect ) ;
23 J_subimage = imcrop (J , rect ) ;
24 figure
25 ShowImage ( I_subimage , ’ Sub Image o f Cameraman Image ’ )
26 figure
27 ShowImage ( J_subimage , ’ Sub Image o f Lenna Image ’ )
28 a =2;
29 b =0.5;
30 M = imlincomb (a ,I ,b , J ) ;
31 figure
32 ShowImage (M , ’ L i n e a r C o m b i n a t i o n o f cameraman and
Lenna Image ’ )
33 N = imlincomb (b ,I ,a , J ) ;
34 figure
35 ShowImage (N , ’ L i n e a r C o m b i n a t i o n o f cameraman and
Lenna Image ’ )
16
Figure 4.1: Exp4
17
Figure 4.2: Exp4
18
Experiment: 5
Affine Transformation - To
learn basic image
transformation i) Translation
ii) Rotation iii) Scaling
1 // Prog5 . A f f i n e T r a n s f o r m a t i o n − To l e a r n b a s i c
image t r a n s f o r m a t i o n
2 // i ) T r a n s l a t i o n i i ) R o t a t i o n i i i ) S c a l i n g
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 clc ;
11 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ; // s i z e 256
x256
19
12 [m , n ] = size ( I ) ;
13 for i = 1: m
14 for j =1: n
15 // S c a l i n g
16 J (2* i ,2* j ) = I (i , j ) ;
17 // R o t a t i o n
18 p = i * cos ( %pi /2) + j * sin ( %pi /2) ;
19 q = -i * sin ( %pi /2) + j * cos ( %pi /2) ;
20 p = ceil ( abs ( p ) +0.0001) ;
21 q = ceil ( abs ( q ) +0.0001) ;
22 K (p , q ) = I (i , j ) ;
23 // s h e a r t r a n s f o r m a t i o n
24 u = i +0.2* j ;
25 v = j;
26 L (u , v ) = I (i , j ) ;
27 end
28 end
29 figure
30 ShowImage (I , ’ o r i g i n a l Image ’ ) ;
31 figure
32 ShowImage (J , ’ S c a l e d Image ’ ) ;
33 figure
34 ShowImage (K , ’ R o t a t e d Image ’ ) ;
35 figure
36 ShowImage (L , ’ S h e a r t r a n s f o r m e d ( x d i r e c t i o n ) Image ’ ) ;
20
Experiment: 6
1 // Prog6 . A f f i n e T r a n s f o r m a t i o n −−To l e a r n t h e r o l e
of interpolation operation
2 // i ) Bi− l i n e a r i i ) Bi−c u b i c i i i ) n e a r e s t n e i g h b o r
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
11 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ; // s i z e 256
x256
21
12 [m , n ] = size ( I ) ;
13 for i = 1: m
14 for j =1: n
15 // S c a l i n g
16 J (1.5* i ,1.5* j ) = I (i , j ) ; // 512 x512 Image
17 end
18 end
19 I_nearest = imresize (J ,[256 ,256]) ; // ’ n e a r e s t ’ −
n e a r e s t −n e i g b o r i n t e r p o l a t i o n
20 I_bilinear = imresize (J ,[256 ,256] , ’ b i l i n e a r ’ ) ; // ’
bilinear ’ − bilinear interpolation
21 I_bicubic = imresize (J ,[256 ,256] , ’ b i c u b i c ’ ) ; // ’
bicubic ’ − bicubic interpolation
22 figure
23 ShowImage ( uint8 ( I_nearest ) , ’ n e a r e s t −n e i g b o r
i n t e r p o l a t i o n ’ );
24 figure
25 ShowImage ( uint8 ( I_bilinear ) , ’ b i l i n e a r − b i l i n e a r
i n t e r p o l a t i o n ’ );
26 figure
27 ShowImage ( uint8 ( I_bicubic ) , ’ b i c u b i c − b i c u b i c
i n t e r p o l a t i o n ’ );
22
Experiment: 7
1 // Prog7 . A f f i n e T r a n s f o r m a t i o n −−To l e a r n t h e e f f e c t
of multiple transformations i ) Significance of
o r d e r i n which one c a r r i e d o u t
2 // S o f t w a r e v e r s i o n
3 //OS Windows7
4 // S c i l a b 5 . 4 . 1
5 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
6 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
7 clc ;
8 clear ;
9 close
10 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
23
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
11 [m , n ] = size ( I ) ;
12 for i = 1: m
13 for j =1: n
14 // s h e a r t r a n s f o r m a t i o n and r o t a t i o n
15 u = i +0.2* j ;
16 v = 0.3* i + j ;
17 M (u , v ) = I (i , j ) ;
18 // s h e a r t r a n s f o r m a t i o n , r o t a t i o n and s c a l i n g
19 N ( u *1.5 , v *1.5) = I (i , j ) ;
20 end
21 end
22 figure
23 ShowImage (I , ’ o r i g i n a l Lenna Image ’ )
24 figure
25 ShowImage (M , ’ S h e a r t r a n s f o r m e d+r o t a t e d Lenna Image ’ )
26 figure
27 ShowImage (N , ’ S h e a r T r a n s f o r m e d+r o t a t e d+s c a l e d Lenna
Image ’ )
24
Experiment: 8
1 // Prog8 . P o i n t O p e r a t i o n s − To l e a r n image
enhancement t h r o u g h p o i n t t r a n s f o r m a t i o n
2 // i ) L i n e a r t r a n s f o r m a t i o n i i ) Non− l i n e a r
transformation
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
25
11 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ r i c e . png ’ ) ;
12 // ( i ) . L i n e a r T r a n s f o r m a t i o n
13 //IMAGE NEGATIVE
14 I = double ( I ) ;
15 J = 255 - I ;
16 figure
17 ShowImage (I , ’ O r i g i n a l Image ’ )
18 figure
19 ShowImage (J , ’ L i n e a r T r a n s f o r m a t i o n −IMAGE NEGATIVE ’ )
20 // ( i i ) Non− l i n e a r t r a n s f o r m a t i o n
21 //GAMMA TRANSFORMATION
22 GAMMA = 0.9;
23 K = I .^ GAMMA ;
24 figure
25 ShowImage (K , ’ Non− l i n e a r t r a n s f o r m a t i o n −GAMMA
TRANSFORMATION ’ )
26
Figure 8.1: Exp8
27
Experiment: 9
Neighborhood Operations - To
learn about neighborhood
operations and use them for i)
Linear filtering ii) Non-linear
filtering
1 // Prog9 . N e i g h b o r h o o d O p e r a t i o n s − To l e a r n a b o u t
n e i g h b o r h o o d o p e r a t i o n s and u s e them f o r
2 // i ) L i n e a r f i l t e r i n g i i ) Non− l i n e a r f i l t e r i n g
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
11 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
28
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
12 I_noise = imnoise (I , ’ s a l t & p e p p e r ’ ) ;
13 figure
14 ShowImage (I , ’ O r i g i n a l Lenna Image ’ )
15 figure
16 ShowImage ( I_noise , ’ N o i s y Lenna Image ’ )
17 // Case 1 : L i n e a r F i l t e r i n g
18 // ( i ) . L i n e a r F i l t e r i n g −Example 1 : A v e r a g e F i l t e r
19 F_linear1 = 1/25* ones (5 ,5) ; // 5 x5 mask
20 I_linear1 = imfilter ( I_noise , F_linear1 ) ; // l i n e a r
f i l t e r i n g −A v e r a g e F i l t e r
21 figure
22 ShowImage ( I_linear1 , ’ L i n e a r A v e r a g e F i l t e r e d N o i s y
Lenna Image ’ )
23 // ( i i ) . L i n e a r F i l t e r i n g − Example 2 : G a u s s i n g
filter
24 hsize = [5 ,5];
25 sigma = 1;
26 F_linear2 = fspecial ( ’ g a u s s i a n ’ , hsize , sigma ) ; //
Linear f i l t e r i n g − gaussian F i l t e r
27 I_linear2 = imfilter ( I_noise , F_linear2 ) ;
28 figure
29 ShowImage ( I_linear2 , ’ L i n e a r G a u s s i a n F i l t e r e d N o i s y
Lenna Image ’ )
30 // Case 2 : Non−L i n e a r F i l t e r i n g
31 // ( i ) . Median F i l t e r i n g
32 F_NonLinear = [3 ,3];
33 I_NonLinear = MedianFilter ( I_noise , F_NonLinear ) ; //
Median F i l t e r 3 x3
34 figure
35 ShowImage ( I_NonLinear , ’ Median F i l t e r e d ( Non−L i n e a r )
N o i s y Lenna Image ’ )
29
Experiment: 10
1 // Prog10 . N e i g h b o r h o o d O p e r a t i o n s −−To s t u d y t h e
e f f e c t o f t h e s i z e o f n e i g h b o r h o o d on t h e r e s u l t
of processing
2 // S o f t w a r e v e r s i o n
3 //OS Windows7
4 // S c i l a b 5 . 4 . 1
5 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
6 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
7 clc ;
8 clear ;
9 close ;
10 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
11 I_noise = imnoise (I , ’ s a l t & p e p p e r ’ ) ;
30
12 FilterSize = [3 3]; // f i l t e r s i z e 3 x3
13 I_3x3 = MedianFilter ( I_noise , FilterSize ) ;
14 I_5x5 = MedianFilter ( I_noise ,[5 5]) ;
15 I_7x7 = MedianFilter ( I_noise ,[7 7]) ;
16 I_9x9 = MedianFilter ( I_noise ,[9 9]) ;
17 figure
18 ShowImage (I , ’ O r i g i n a l Lenna Image ’ )
19 figure
20 ShowImage ( I_noise , ’ O r i g i n a l Lenna Image ’ )
21 figure
22 ShowImage ( I_3x3 , ’ F i l t e r e d Lenna Image− F i l t e r size 3
x3 ’ )
23 figure
24 ShowImage ( I_5x5 , ’ F i l t e r e d Lenna Image− F i l t e r size 5
x5 ’ )
25 figure
26 ShowImage ( I_7x7 , ’ F i l t e r e d Lenna Image− F i l t e r size 7
x7 ’ )
27 figure
28 ShowImage ( I_9x9 , ’ F i l t e r e d Lenna Image− F i l t e r size 9
x9 ’ )
31
Experiment: 11
Image Histogram - To
understand how frequency
distribution can be used to
represent an image.
32
12 scf (0)
13 ShowImage (I , ’ O r i g i n a l Image p o u t . png ’ )
14 scf (1) ;
15 plot2d3 ( ’ gnn ’ , cells , count )
16 title ( ’ H i s t o g r a m P l o t o f O r i g i n a l Image ’ )
17 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
h i s t e q . s c i ’ );
18 Iheq = histeq ( I ) ;
19 [ count , cells ]= imhist ( Iheq ) ;
20 scf (2)
21 ShowImage ( Iheq , ’ H i s t o g r a m E q u a l i z e d Image p o u t . png ’ )
22 scf (3)
23 plot2d3 ( ’ gnn ’ , cells , count )
24 title ( ’ H i s t o g r a m o f H i s t o g r a m E q u a l i z e d Image ’ )
histeq.sci
33
Figure 11.1: Exp11
34
Experiment: 12
35
12 [ count , cells ]= imhist ( I ) ;
13 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
DIP Lab2 \ h i s t e q . s c i ’ ) ;
14 Iheq = histeq ( I ) ;
15 [ count1 , cells1 ]= imhist ( Iheq ) ;
16 Corr_Bet_Same_Images = corr2 (I , Iheq ) ;
17 disp ( Corr_Bet_Same_Images , ’ C o r r e l a t i o n b e t w e e n
o r i g i n a l Image and I t s H i s t o g r a m e q u a l i z e d Image ’
)
18 J = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ cameraman . j p e g ’ ) ;
19 Corr_Bet_Diff_Images = corr2 ( Iheq , J ) ;
20 disp ( Corr_Bet_Diff_Images , ’ C o r r e l a t i o n b e t w e e n p o u t .
png and cameraman . j p e g i m a g e s ’ )
21 x = xcorr ( count , count ) ; // c o r r e l a t i o n o f h i s t o g r a m
o f t h e same
22 x1 = xcorr ( count , count1 ) ; // c o r r e l a t i o n o f h i s t o g r a m
o f o r i g i n a l image and i t s h i s t o g r a m e q u a l i z e d
image
23 scf (0)
24 plot2d3 ( ’ gnn ’ ,1: length ( x ) ,x ,5)
25 title ( ’ c o r r e l a t i o n b e t w e e n h i s t o g r a m s o f o r i g i n a l
image ’ )
26 scf (1)
27 plot2d3 ( ’ gnn ’ ,1: length ( x1 ) ,x1 ,5)
28 title ( ’ c o r r e l a t i o n b e t w e e n h i s t o g r a m s o f o r i g i n a l
image and i t s h i s t o g r a m e q u a l i z e d image ’ )
29 //RESULT
30 // C o r r e l a t i o n b e t w e e n o r i g i n a l Image and I t s
H i s t o g r a m e q u a l i z e d Image
31 //
32 // 0.9784662
33 //
34 // C o r r e l a t i o n b e t w e e n p o u t . png and cameraman . j p e g
images
35 //
36 // − 0 . 3 2 0 4 2 5 9
37 //
36
check Appendix AP 3 for dependency:
histeq.sci
37
Experiment: 13
Fourier Transform: To
understand some of the
fundamental properties of the
Fourier transform.
1 // Prog13 . F o u r i e r T r a n s f o r m : To u n d e r s t a n d some o f
the fundamental p r o p e r t i e s of the Fourier
transform .
2 // S o f t w a r e v e r s i o n
3 //OS Windows7
4 // S c i l a b 5 . 4 . 1
5 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
6 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
7 clc ;
8 clear ;
9 close ;
10 I = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ DIP Lab2 \ l e n n a . j p g ’ ) ;
11 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
38
DIP Lab2 \ f f t 2 d . s c i ’ ) ;
12 exec ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \ Gautam PAL Lab \
DIP Lab2 \ i f f t 2 d . s c i ’ ) ;
13 // [ 1 ] . 2 D−DFT and i t s I n v e r s e 2D−DFT
14 I = double ( I ) ;
15 J = fft2d ( I ) ;
16 K = real ( ifft2d ( J ) ) ;
17 figure
18 ShowImage (I , ’ O r i g i n a l Lenna Image ’ )
19 figure
20 ShowImage ( abs ( J ) , ’ 2D DFT ( s p e c t r u m ) o f Lenna Image ’ )
21 figure
22 ShowImage (K , ’ 2 d IDFT o f Lenna Image ’ )
23 // [ 2 ] . Two t i m e s f f t s h i f t r e s u l t s i n o r i g i n a l
spectrum
24 L = fftshift ( J ) ;
25 M = fftshift ( L ) ;
26 figure
27 ShowImage ( abs ( L ) , ’ f f t s h i t e d s p e c t r u m o f Lenna Image ’
)
28 figure
29 ShowImage ( abs ( M ) , ’ two t i m e s f f t s h i f t e d ’ )
fft2d.sci
ifft2d.sci
39
Experiment: 14
1 // Prog14 . C o l o u r Image P r o c e s s i n g : To l e a r n c o l o u r
i m a g e s a r e h a n d l e d and p r o c e s s e d
2 // i ) Models f o r r e p r e s e n t i n g c o l o u r i i ) Methods o f
proces
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
40
11 RGB = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
Gautam PAL Lab \ D I P l a b 2 \ f o o t b a l l . j p g ’ ) ;
12 figure
13 ShowColorImage ( RGB , ’RGB C o l o r Image ’ )
14 YIQ = rgb2ntsc ( RGB ) ;
15 figure
16 ShowColorImage ( YIQ , ’NTSC image YIQ ’ )
17 RGB = ntsc2rgb ( YIQ ) ;
18 YCC = rgb2ycbcr ( RGB ) ;
19 figure
20 ShowColorImage ( YCC , ’ e q u i v a l e n t HSV image YCbCr ’ )
21 RGB = ycbcr2rgb ( YCC ) ;
22 HSV = rgb2hsv ( RGB ) ;
23 figure
24 ShowColorImage ( HSV , ’ e q u i v a l e n t HSV image ’ )
25 RGB = hsv2rgb ( HSV ) ;
26 R = RGB (: ,: ,1) ;
27 G = RGB (: ,: ,2) ;
28 B = RGB (: ,: ,3) ;
29 figure
30 ShowImage (R , ’ Red M a t r i x ’ )
31 figure
32 ShowImage (G , ’ Green M a t r i x ’ )
33 figure
34 ShowImage (B , ’ B l u e M a t r i x ’ )
41
Figure 14.1: Exp14
42
Experiment: 15
Morphological Operations: To
understand the basics of
morphological operations which
are used in analyzing the form
and shape de
1 // Prog15 . M o r p h o l o g i c a l O p e r a t i o n s : To u n d e r s t a n d t h e
basics of morphological operations
2 // which a r e u s e d i n a n a l y z i n g t h e form and s h a p e
3 // S o f t w a r e v e r s i o n
4 //OS Windows7
5 // S c i l a b 5 . 4 . 1
6 // Image P r o c e s s i n g D e s i g n T o o l b o x 8 . 3 . 1 − 1
7 // S c i l a b Image and V i d e o P r o c c e s s i n g t o o l b o x
0.5.3.1 −2
8 clc ;
9 clear ;
10 close ;
11 Image = imread ( ’C : \ U s e r s \ s e n t h i l k u m a r \ D e s k t o p \
43
Gautam PAL Lab \ DIP Lab2 \ t i r e . j p e g ’ ) ;
12 StructureElement = CreateStructureElement ( ’ s q u a r e ’
,3) ; // g e n e r a t e s t r u c t u r i n g e l e m e n t IPD atom
13 ResultImage1 = ErodeImage ( Image , StructureElement ) ;
// IPD Atom
14 ResultImage2 = DilateImage ( Image , StructureElement ) ;
// IPD Atom
15 ResultImage3 = BottomHat ( Image , StructureElement ) ;
// IPD Atom
16 ResultImage4 = TopHat ( Image , StructureElement ) ; //
IPD Atom
17 figure
18 ShowImage ( Image , ’ O r i g i n a l Image ’ )
19 figure
20 ShowImage ( ResultImage1 , ’ Eroded Image ’ )
21 figure
22 ShowImage ( ResultImage2 , ’ D i l a t e d Image ’ )
23 figure
24 ShowImage ( ResultImage3 , ’ bottom h a t f i l t e r e d image ’ )
25 figure
26 ShowImage ( ResultImage4 , ’ t o p h a t f i l t e r e d image ’ )
27
28 ResultImage5 = imadd ( ResultImage3 , ResultImage4 ) ;
29 figure
30 ShowImage ( ResultImage4 , ’ t o p h a t f i l t e r e d image+
bottom h a t f i l t e r e d image ’ )
44
Figure 15.1: Exp15
45
Appendix
46
2D Fast Fourier Trasnform
47
16 sb = uint8 ( round ( s ) ) ;
17 index =0;
18 for i =1: m
19 for j =1: n
20 index = double ( a (i , j ) ) +1; // c o n v e r t i t t o
double
21 // o t h e r w i s e i n d e x = 255+1 =0
22 hea (i , j ) = sb ( index ) ; // h i s t o g r a m
equalization
23 end
24 end
25 endfunction
Histogram Equalization
48
2 // pad z e r o s i n c o l u m n s and r o w s a t b o t h e n d s o f
an b i n a r y image
3 [m , n ] = size ( b ) ;
4 num_dims = length ( size ( b ) ) ;
5 B = zeros ( m + num_dims , n + num_dims ) ;
6 for i = num_dims : m + num_dims -1
7 for j = num_dims : m + num_dims -1
8 B (i , j ) = b (i -1 ,j -1) ;
9 end
10 end
11 endfunction
Pad Array
49