digital image processing

21
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. 1

Upload: adnan-shah

Post on 25-Oct-2014

140 views

Category:

Documents


5 download

TRANSCRIPT

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.

1

2

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 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9

>> B = rand(5)

B =

0.8147 0.0975 0.1576 0.1419 0.6557 0.9058 0.2785 0.9706 0.4218 0.0357 0.1270 0.5469 0.9572 0.9157 0.8491 0.9134 0.9575 0.4854 0.7922 0.9340 0.6324 0.9649 0.8003 0.9595 0.6787

2

3

>> C = A+BC =

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 9.0866 11.0425 18.5146 20.2078 2.0660 10.3676 17.0351 24.1997 1.0405 8.3213

>> E=A*B

E =

52.5087 31.0224 42.8180 34.1801 30.5068 47.0615 36.3074 34.7780 38.2251 45.1402 42.5239 49.5483 46.2109 51.9557 47.4880 42.5075 37.7104 44.0031 43.3938 44.7695 35.9589 30.3570 51.3069 42.2657 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)

3

4

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 23 4 10 11 24 5 6 12 18 1 7 13 19 25 8 14 20 21 2 15 16 22 3 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,

4

5

plot(t,B)title('cos')

OUTPUT

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1sin

5

6

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1cos

EXPERIMENT NO. 3

INPUT

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

OUTPUT

6

7

EXPERIMENT NO.4

INPUT

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

OUTPUT

7

8

EXPERIMENT NO. 5

INPUT

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

8

9

OUTPUT:

0

1000

2000

3000

4000

5000

6000

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

LAB No. 2:

Basic Functions Of DIP in MATLAB

INPUT

a = imread('C:\\pakistan.jpg');subplot(4,2,[1 2])

9

10

imshow(a)title('Original')

whos ainfo aimfinfo('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);title('Array Indexing')

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

OUTPUT:

10

11

LAB No. 3:

Image Segmentation Processing in MATLAB

INPUT

a = imread('c:\\pakistanl.jpg')

11

12

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 Imagefor i=1:m for j=1:n if(c(i,j)>128) d(i,j) = 1; else d(i,j) = 0; end endendsubplot(4,2,3)imshow(d)title('Binary')

%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;

12

13

else e(i,j) = 0; end endendsubplot(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 endendsubplot(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; end endendsubplot(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;

13

14

end endendsubplot(4,2,7)imshow(h) title('4th Segment')

OUTPUT

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')

14

15

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 endend

r1=[m];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

15

16

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

OUTPUT

16

17

LAB No. 5:

Image Enhancement in MATLAB

INPUT

17

18

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 Imaged = imcomplement(c)subplot(4,2,4)imshow(d);title('Negetive')

%Log Transformationconst=0.2;e = const*log(1+ double(c));subplot(4,2,5)imshow(e);title('Log Transformation')

%adjustf = imadjust(c,[0.1 0.5],[0.5 0.9],[]);subplot(4,2,6)imshow(f);title('Adjustment')

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

f = imadjust(c,[],[],3);subplot(4,2,8)imshow(f);

18

19

title('Power Law Transformation’)

OUTPUT:

19