You are on page 1of 17

DIP Practical Assignment

Q1 W. A. P. Monochrome image and Colour Image.

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('monochrome image');
j=imread('C:\Users\yoges\OneDrive\Desktop\Pictures\flower.png');
figure,
imshow(j);
title(' colour image');

Output

colour image
monochrome image
Q2 W. A. P. for colour Model as

➢ RGB to HSV & HSV to RGB

clear all;
close all;
j=imread('C:\Users\yoges\OneDrive\Desktop\Pictures\flower.png');
figure,
imshow(j);
title('original image');
k=rgb2hsv(j);
figure,
imshow(k);
title('HSV image');
l=hsv2rgb(k);
figure,
imshow(l);
title('RGB image');

Output
original image HSV image

RGB image
➢ RGB to YCBCR & YCBCR to RGB

clear all;
close all;
j=imread('C:\Users\yoges\OneDrive\Desktop\Pictures\flower.png');
figure,
imshow(j);
title('original image');
k=rgb2ycbcr(j);
figure,
imshow(k);
title('YCBCR image');
l=ycbcr2rgb(k);
figure,
imshow(l);
title('RGB image');

Output

YCBCR image

original image

RGB image
➢ RGB to NTSC & NTSC to RGB

clear all;
close all;
j=imread('C:\Users\yoges\OneDrive\Desktop\Pictures\flower.png');
figure,
imshow(j);
title('Original image');
k=rgb2ntsc(j);
figure,
imshow(k);
title('NTSC image');
l=ntsc2rgb(k);
figure,
imshow(l);
title('RGB image');

Output

original image NTSC image

RGB image
Q3 W.A.P. to convert colour image into monochrome image.

clear all;
close all;
j=imread('C:\Users\yoges\OneDrive\Desktop\Pictures\flower.png');
figure,
imshow(j);
title('colour image');
k=rgb2gray(j);
figure,
imshow(k);
title('monochrome image');

Output

monochrome image

colour image
Q4 W.A.P. to separate individual component of colour image.

clear all;
close all;
k=imread('C:\Users\yoges\OneDrive\Desktop\Final Project\images\laptop.png');
figure,
imshow(k);
title('Original image');
j=k(:,:,1);
figure,
imhist(j);
title('Red image Graph');
j1=k(:,:,2);
figure,
imhist(j1);
title('Green image Graph');
j2=k(:,:,3);
figure,
imhist(j2);
title('Blue image Graph');

Output

Red image Graph


Original image

9000

8000

7000

6000

5000

4000

3000

2000

1000

0 50 100 150 200 250

Blue image Graph Green image Graph


9000 9000

8000 8000

7000 7000

6000 6000

5000 5000

4000 4000

3000 3000

2000 2000

1000 1000

0
0

0 50 100 150 200 250


0 50 100 150 200 250
Q5 W.A.P. to display simple histogram.

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('Original image');
figure,
imhist(i);
title('Histogram image');

Output

Histogram image
Original image
1000

900

800

700

600

500

400

300

200

100

0 50 100 150 200 250


Q6 W.A.P to display equalised histogram.

clear all;
close all;
i=imread('tire.tif');
figure,
imshow(i);
title('original image');
figure,
imhist(i);
title('simple histogram');
j=histeq(i);
figure,
imshow(j);
title('equilised image');
figure,
imhist(i);
title('Equilised histogram');

Output

original image simple histogram

800

600

400

200

0 50 100 150 200 250

Equilised histogram

equilised image 1000

900

800

700

600

500

400

300

200

100

0 50 100 150 200 250


Q7 W.A.P. to display simple histogram along with type of histogram.

clear all;
close all;
i=imread('cameraman.tif');
k=i(1:10:255);
figure,
imshow(i);
title('Original image');
figure,
bar(k);
title('Bar image');
figure,
plot(k);
title('Plot image');
figure,
stem(k);
title('Stem image');

OUTPUT
Original image Bar image
180

160

140

120

100

80

60

40

20

0
0 5 10 15 20 25 30

Plot image Stem image


170 180

160 160

150 140

140 120

130 100

120 80

110 60

100 40

90 20

80 0
0 5 10 15 20 25 30 0 5 10 15 20 25 30
Q8 W.A.P. to obtain the complement of monochrome image using imadjust function

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('orignal image');
j=imadjust(i,[0 1] ,[1 0]);
figure,
imshow(j);
title('complemented image');

Output

orignal image complemented image


Q9 W.A.P.to obtain the complement of monochrome image using imcomplement function

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('Original image');
j=imcomplement(i);
figure,
imshow(j);
title('complemented image');

Output

orignal image complemented image


Q10 W.A.P. implement median filter.

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('original image');
j=imnoise(i,'salt & pepper',0.04);
figure,
imshow(j);
title('noisy image');
k=medfilt2(j);
figure,
imshow(k);
title('median image');

Output

noisy image
original image

median image
Q11 W.A.P. demonstration of noise.

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('original image');
j=imnoise(i,'salt & pepper',0.04);
figure,
imshow(j);
title('noisy image');

Output
original image
noisy image
Q12 W.A.P. to display edges using edge detection technique.

clear all;
close all;
i=imread('rice.png');
figure,
imshow(i);
title('Original image');
j = edge(i,'sobel');
figure,
imshow(j);
title('Sobel image');
k = edge(i,'canny');
figure,
imshow(k);
title('canny image');
l= edge(i,'prewitt');
figure,
imshow(l);
title('prewitt image');

Output

Original image Sobel image

prewitt image
canny image
Q13 W.A.P. to rotate monochrome image

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('original image');
j=imrotate(i,90);
figure,
imshow(j);
title('rotated image');

OUTPUT

rotated image
original image
Q14 W.A.P. to obtain 2D DFT in matlab

clear all;
close all;
i=imread('cameraman.tif');
figure,
imshow(i);
title('original image');
i1=fft2(i);
figure,
imshow(i1);
title('2D DFT image');
i2=abs(i1);
i3=fftshift(i2);
figure,
imshow(mat2gray(i3));
title('abs 2D DFT image');
i4=log(1+abs(i3));
figure,
imshow(mat2gray(i4));
title('log 2D DFT image');
i5 = ifftshift(i3);
i6 = ifft2(i1);
figure,
imshow(mat2gray(i6));
title(' inverse image 2D DFT');

Output
original image 2D DFT image

abs 2D DFT image log 2D DFT image inverse image 2D DFT


Q15 perform and demonstrate matrix operations in command window.

>> a=[2 6;5 7]

a=

2 6

5 7

>> b=[5 3;4 6]

b=

5 3

4 6

>> a=a-1 %subtraction %

a=

1 5

4 6

>> c=a+b % Addition%

c=

6 8

8 12

>> d=a*2 % Multiplication%

d=

2 10

8 12

>> e=[8 6; 4 10;]

e=

8 6

4 10

>> f=e/2 %Division%

f=

4 3

2 5

You might also like