Sei sulla pagina 1di 19

1

LAB Manual (Mid Term)

Digital Image Processing By Using


MATLAB.

Submitted To:

Engr. M. Anees
Submitted By:

Naqash Rasheed
08-CS-39.

Department Of Computer Systems


Engineering.

University College of Engineering &


Technology.

The Islamia University of Bahawalpur,


Pakistan.

LAB No. 1:
Introduction to MATLAB

EXPERIMENT No.1
>> A = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
A=
17
23
4
10
11

24 1 8 15
5 7 14 16
6 13 20 22
12 19 21 3
18 25 2 9

>> B = rand(5)
B=
0.8147
0.9058
0.1270
0.9134
0.6324

0.0975
0.2785
0.5469
0.9575
0.9649

0.1576
0.9706
0.9572
0.4854
0.8003

0.1419
0.4218
0.9157
0.7922
0.9595

0.6557
0.0357
0.8491
0.9340
0.6787

>> C = A+B
C=
17.8147 24.0975 1.1576 8.1419 15.6557
23.9058 5.2785 7.9706 14.4218 16.0357
4.1270 6.5469 13.9572 20.9157 22.8491
10.9134 12.9575 19.4854 21.7922 3.9340
11.6324 18.9649 25.8003 2.9595 9.6787
>> D =A-B
D=
16.1853 23.9025 0.8424 7.8581 14.3443
22.0942 4.7215 6.0294 13.5782 15.9643
3.8730 5.4531 12.0428 19.0843 21.1509
3

9.0866 11.0425 18.5146 20.2078


10.3676 17.0351 24.1997 1.0405

2.0660
8.3213

>> E=A*B
E=
52.5087
47.0615
42.5239
42.5075
35.9589

31.0224
36.3074
49.5483
37.7104
30.3570

42.8180
34.7780
46.2109
44.0031
51.3069

34.1801
38.2251
51.9557
43.3938
42.2657

30.5068
45.1402
47.4880
44.7695
37.0608

>> F =A/B
F=
-88.5273 35.7779 26.1898 167.6415 -157.7070
135.3219 -54.0530 -54.2699 -193.5970 229.9789
95.9363 -47.6970 -17.8507 -145.5081 164.7995
87.0939 -36.2909 -42.4594 -163.8328 200.7518
-273.0120 143.6205 130.6820 456.6886 -522.4628
>> G =inv(A)
G=
-0.0049 0.0512 -0.0354 0.0012 0.0034
0.0431 -0.0373 -0.0046 0.0127 0.0015
-0.0303 0.0031 0.0031 0.0031 0.0364
0.0047 -0.0065 0.0108 0.0435 -0.0370
0.0028 0.0050 0.0415 -0.0450 0.0111
>> H =A'
H=
17
24
1

23 4 10 11
5 6 12 18
7 13 19 25
4

8 14 20 21
15 16 22 3

2
9

>> I = eig(B)
I=
3.2037
0.5684
-0.1026 + 0.5388i
-0.1026 - 0.5388i
-0.0457

EXPERIMENT NO.2
INPUT
t = 0 : 0.1 :5;
A = sin(t);
B = cos(t);
plot(t,A)
title('sin')
figure,
plot(t,B)
title('cos')

OUTPUT

sin
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5

2.5

3.5

4.5

cos
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5

2.5

3.5

4.5

EXPERIMENT NO. 3

INPUT
P = imread('C:\\pakistan.jpg');
P= im2double(P);
imshow(P)

OUTPUT

EXPERIMENT NO.4

INPUT
P = magic(10)
I = im2double(P);
imshow(I)

OUTPUT

EXPERIMENT NO. 5

INPUT
P= imread('c:\\pakistan.jpg');
P = im2double(P);
imshow(P)
figure,
imhist(P)
OUTPUT:

6000

5000

4000

3000

2000

1000

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

10

LAB No. 2:
Basic Functions Of DIP in MATLAB

INPUT
a = imread('C:\\pakistan.jpg');
subplot(4,2,[1 2])
imshow(a)
title('Original')
whos a
info a
imfinfo('football.jpg')
b = imresize(a,[4,4])
subplot(4,2,3)
imshow(b)
title('Resize 4x4')
c = imresize(a,[128,128])
subplot(4,2,4)
imshow(c)
title('Resize 128x128')
d = imrotate(a,60)
subplot(4,2,5)
imshow(d)
title('Rotated by 60')
e = im2bw(a,0.6)
subplot(4,2,6)
imshow(e)
title('Binary')
f=rgb2ind(a,32);
subplot(4,2,6)
imshow(f);
10

11

title('Array Indexing')
g=rgb2gray(a)
subplot(4,2,7)
imshow(g)
title('Grayscale');

OUTPUT:

11

12

LAB No. 3:
Image Segmentation Processing in MATLAB
INPUT
a = imread('c:\\pakistanl.jpg')
b = imresize(a, [512 512]);
subplot(4,2,1)
imshow(b)
title('Resized')
c = rgb2gray(b);
subplot(4,2,2)
imshow(c)
title('GrayScale')
[m n]=size(c);
d = zeros(m,n)

%Conversion to Binary Image


for i=1:m
for j=1:n
if(c(i,j)>128)
d(i,j) = 1;
else
d(i,j) = 0;
end
end
end
subplot(4,2,3)
imshow(d)
title('Binary')

12

13

%Processing on Segmentation
e = zeros(m/2,n/2)
f = zeros(m/2,n/2)
g = zeros(m/2,n/2)
h = zeros(m/2,n/2)
for i=1:m/2
for j=1:n/2
if(c(i,j) >128)
e(i,j) = 1;
else
e(i,j) = 0;
end
end
end
subplot(4,2,4)
imshow(e)
title('1/4th Segment')
for i=1:m/2
for j=n/2:n
if(c(i,j) >128)
f(i,j-255) = 1;
else
f(i,j-255) = 0;
end
end
end
subplot(4,2,5)
imshow(f)
title('1/2th Segment')
for i=m/2:m
for j=1:n/2
if(c(i,j) >128)
g(i-255,j) = 1;
else
g(i-255,j) = 0;
13

14

end
end
end
subplot(4,2,6)
imshow(g)
title('3/4th Segment')
for i=m/2:m
for j=n/2:n
if(c(i,j) >128)
h(i-255,j-255) = 1;
else
h(i-255,j-255) = 0;
end
end
end
subplot(4,2,7)
imshow(h)
title('4th Segment')

OUTPUT

14

15

LAB No. 4:
Line Algorithms Based Image Scanning in MATLAB
INPUT
a = imread('c:\\pakistan.jpg');
subplot(2,2,[1 2])
imshow(a)
title('Original')
b=imresize(a ,[512 512]);
subplot(2,2,3)
imshow(b)
title('Resize by 512x512')
c=rgb2gray(b);
subplot(2,2,4)
imshow(c)
%d=zeros(1,300);
[m, n]=size(c);
d=[m n];
d=zeros(1,100);
for i=1:m
for j=1:n
if(c(i,j)<=128 )
d(i,j) = 1;
else
d(i,j) = 0;
end
end
end

r1=[m];
15

16

c1=[n];
r1=zeros(r1);
c1=zeros(c1);
l=zeros(1,3)
for i=2:m
for j=2:n
if(c(i,j)==1 )
if(d(i,j-1)==0 & d(i-1,j)==0)
r1(i-1)=i;
c1(j-1)=j;
l(i,j)=1
end
if(d(i,j-1)==0 & d(i-1,j)==1)
r1(i-1)=i;
c1(j-1)=j;
l(i,j)=1;
% l1(r1,c1)=1;
end
if(d(i,j-1)==1 & d(i-1,j)==0)
r1(i-1)=i;
c1(j-1)=j;
%l(i,j)=l1;
end
else if(d(i,j-1)==1 & d(i-1,j)==1)
r1(i-1)=i;
c1(j-1)=j;
% l(i,j)=l2;
end
end
end
end

16

17

OUTPUT

17

18

LAB No. 5:
Image Enhancement in MATLAB
INPUT
a = imread('c:\\pakistan.jpg');
subplot(4,2,[1 2])
imshow(a);
title('Original')
b = rgb2gray(a);
c = imresize(b,[256,256]);
subplot(4,2,3)
imshow(c);
title('Graycale')
%negetive of Image
d = imcomplement(c)
subplot(4,2,4)
imshow(d);
title('Negetive')
%Log Transformation
const=0.2;
e = const*log(1+ double(c));
subplot(4,2,5)
imshow(e);
title('Log Transformation')
%adjust
f = imadjust(c,[0.1 0.5],[0.5 0.9],[]);
subplot(4,2,6)
imshow(f);
title('Adjustment')

18

19

%Contrast Stretching
f = imadjust(c,[],[],0.3);
subplot(4,2,7)
imshow(f);
title('Contast Stretching')

f = imadjust(c,[],[],3);
subplot(4,2,8)
imshow(f);
title('Power Law Transformation)
OUTPUT:

19

Potrebbero piacerti anche