0% found this document useful (0 votes)
13 views

Dip Lab Manual 13-2-23

Uploaded by

Prerna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Dip Lab Manual 13-2-23

Uploaded by

Prerna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

DIGITAL IMAGE PROCESSING

LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 01
Experiment name: Program to read, display
and write a gray scale image

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

1
Experiment-1
Aim: – Program to read, display and write a gray scale image
Apparatus: - MATLAB software
Program:-
A=imread('cameraman.tif');
figure(1);
imshow(A);
imwrite(A,'cameraman.png');%write to png format
figure(2);
imshow(A);

Output image:-

Result: – A gray scale image is read using imread function. The some image is
displayed using imshow function. The read file is saved to another file format by
using imwrite function.

VIVA QUESTIONS:

2
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET
EXPERIMENT NO – 02
Experiment name: Program to read, display
and write an index Image

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

3
Experiment-2
Aim: – Program to read, display and write an index Image
Apparatus: - MATLAB software
Program:-
[A,map]=imread('trees.tif');
figure(1);
imshow(A,map);
title('TIF');
imwrite(A,map,'trees.gif');%write to gif
figure(2);
imshow('trees.gif');
title('GIF');

Output image:-
GIF TIF

Result: – An indexed image is read using imread function. The some image is
displayed using imshow function. The read file is saved to another file format by
using imwrite function.

VIVA QUESTIONS:

4
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 03
Experiment name: Program to convert a
true color image to an indexed image

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-3

5
Aim: – Program to convert a true colour image to an indexed image
Apparatus: - MATLAB software
Program:-
A=imread('onion.png');
figure(1);
imshow(A);
title('tree colour PNG');
[X,map]=rgb2ind(A,256);
%mapping tree colour to indexed
imwrite(X,map,'onion.jpg');
figure(2);
imshow('onion.jpg');
title('Indexed JPEG');

Output image:-
tree colour PNG Indexed JPEG

Result: – A true colour image is converted to index image by using the function
rgb2ind
VIVA QUESTIONS:

6
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 04
Experiment name: Program to convert an
RGB image to gray scale image

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

7
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-4
Aim: –Program to convert an RGB image to gray scale image
Apparatus: - MATLAB software
Program:-
I=imread('onion.png');
figure(1);
imshow(I);
title('RGB');
J=rgb2gray(I);
figure(2),imshow(J);
title('grey scale image');

Output image:-
RGB grey scale image

8
Result: – An RGB image is converted to gray scale image by using the function
rgb2gray
VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 05
Experiment name: Program to find the details
and compression ratio of an image file format
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

9
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-5
Aim:-Program to find the details and compression ratio of an image file format
Apparatus: - MATLAB software
Program:-
A=imread('onion.png')
i=imfinfo('onion.png')
h=i.Width*i.Height*i.BitDepth/8
j=i.FileSize
Compression_ratio=h/j

Output:-
h =80190
j = 52404
Compression _ratio = 1.5302

10
Result: - The image information is obtained using function imfinfo. The
compression ratio of the image file format is also evaluated

VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 06
Experiment name: Program to perform
Histogram equalization
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

11
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-6
Aim: - Program to perform Histogram equalization
Apparatus: - MATLAB software
Program:-
clc; closeall; clearall;
f=imread('pout.tif');%figure1
subplot(2,2,1);
imshow(f);
title('Original Image');
subplot(2,2,2);
imhist(f);
ylim('auto');
title('Equalized Image');
g=histeq(f,256);%figure1
subplot(2,2,3);
imshow(g);
title('Histogram of Original Image');
subplot(2,2,4);
12
imhist(g);
ylim('auto');
title('Histogram of Equalized Image');

Output image:-
Original Image Equalized Image
4000

3000

2000

1000

0
0 100 200

Histogram of Original Image Histogram of Equalized Image


4000

3000

2000

1000

0
0 100 200

Result: – I have done histogram equalization

VIVA QUESTIONS:

13
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 07
Experiment name: Program to perform an
image histogram

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

14
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-7
Aim:–Program to perform an image histogram
Apparatus: - MATLAB software
Program:-
clc;
clear all;
close all;
I=imread('cameraman.tif');
subplot(231);
imshow(I);title('input image');
h=imhist(I,256);
subplot(232);
imhist(I);
title('histogram using imhist function');
ylim('auto');
h1=h(1:10:256);
horz=1:10:256;
subplot(233);
bar(horz,h1);
title('histogram using bar function');
subplot(234);
stem(horz,h1,'fill');
title('histogram using steam function ');
subplot(235);

15
plot(h);
title('histogram using plot function');

Output image:-
histogram using imhist function gram using bar function
histo
input image 2000 1500

1500
1000
1000

500 500

0
0
0 100 200 -500 0 500

histogram using steam functio


hn
istogram using plot function
1500 2000

1500
1000
1000
500
500

0 0
0 200 400 0 200 400

Result: –I have done an image histogram


VIVA QUESTIONS:

16
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET
EXPERIMENT NO – 08
Experiment name: Program to read an image
filtering in spatial domain

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

17
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-8
Aim: -Program to read an image filtering in spatial domain
Apparatus: - MATLAB software
Program:-
Clc; clearall; closeall;
I=imread('eight.tif');
subplot(131);
imshow(I);
title('input image');
I_noise=imnoise(I,'salt & pepper',0.02);
subplot(132);
imshow(I_noise);
title('noisy image');
J=medfilt2(I_noise,[3 3]);
subplot(133);
imshow(J);
title('filtered image');

18
Output image:-

input image noisy image filtered image

Result: - I have done an image filtering in spatial domain


VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 09
Experiment name: To perform frequency
domain method low pass filtering
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
19
(Mrs. Sarika sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-9
Aim: - To perform frequency domain method low pass filtering
Apparatus: - MATLAB software
Program:-
I=imread('cameraman.tif');
[M,N]=size(I);
for u=1:M
for v=1:N
D(u,v)=(((u-(M/2))^2+(v-(N/2)))^2)^(1/2);
end
end
for u=1:M
for v=1:N
H(u,v)=1/(1+(D(u,v)/20)^4);
end
end
F=fft2(I);%take fft of input image
F=fftshift(F); %preprocessing
Y=F.*H; % multipling fft of image and tf
Y1=ifftshift(Y); %postpocessing
20
y=ifft2(Y1); % taking inverse
subplot(1,2,1)
imshow(I);
title('original image');
subplot(1,2,2)
imshow(uint8(y))
title('lowpass filterred image')

Output image:-

original image lowpass filterred image

Result:- I have done To perform frequency domain method low pass filtering
21
VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 10
Experiment name: To perform morphological
operation dilating an image

Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

22
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-10
Aim: - To perform morphological operation dilating an image
Apparatus: - MATLAB software
Program:-
clc; clearall; closeall;
I=imread('text.png');
se=strel('line',11,90);
%line shaped structuring element of length 11 and % angle 90degree
A=imdilate(I,se);
subplot(121);
imshow(I);
title('original binary image');
subplot(122);
imshow(A);
title('dilated binary image');

Output image:-

23
origional binary image dilated binary image

Result:- I have done morphological operation dilating an image


VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 11
Experiment name: To perform morphological
operation erosion an image
Prepared by

24
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-11
Aim: - To perform morphological operation erosion an image
Apparatus: - MATLAB software
Program:-
%erosion using disk shaped structuring element
element of radius 14
B=imerode(I,Se) clc;clearall;closeall;
I=imread('circles.png')
Se=strel('disk',14);
%disk shapedstructuring
subplot(121)
imshow(I)
title('original Binary image')
subplot(122)
imshow(B)
title('Eroded Binary image')

25
Output image:-

origional Binary image Eroded Binary image

Result:- I have done morphological operation erosion an image


VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 12
Experiment name: To perform morphological
operation opening and closing
Prepared by

26
(Dr. S.K. Agrawal) Assistant Professor,

(Mrs. Sarika sharma) Lab


Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-12
Aim: - To perform morphological operation opening and closing
Apparatus: - MATLAB software
Program:-
I=imread('circles.png')
Se=strel('disk',14)
C=imopen(I,Se)
D=imclose(I,Se)
subplot(131)
imshow(I);title('original image')
subplot(132)
imshow(C)
title('After morphological opening')
subplot(133)
imshow(D)
title('After morphological closing')
Output image:-

27
origional image After morphologycal opening
After morphologycal closing

Re
sult:- I have done morphological operation erosion an image
VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET
EXPERIMENT NO. – 13
Experiment name: To perform threshold
based segment
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika sharma) Lab Technician
28
Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-13
Aim: - To perform threshold based segment
Apparatus: - MATLAB software
Program:-
clc; clearall; closeall;
I=imread('cameraman.tif')
imshow(I)
Min_d=double(min(I(:)))
Max_d=double(max(I(:)))
% calculate initial threshold
T_init=0.5*(Min_d+Max_d)
done=false; %initialising condition for loop
T_manual=T_init
while~done%starting the iteration loop
image_area1=I>=T_manual

29
image_area2=I<=T_manual
m1=mean(I(image_area1))
m2=mean(I(image_area2))
T=0.5*(m1+m2)
done=abs(T_manual-T)<0.5
%Final threshold after iteration
T_manual=T
end
T_fun=graythresh(I)*255
T_manual=T_manual/255
I_segment=im2bw(I,T_manual)
figure
imshow(I_segment)
%im2bw converts an image into Bw image

Output image:-
m1 =153.3484 , m2 = 23.7291, T = 88.5388, done =1,
T_manual = 88.5388, T_fun =88, T_manual = 0.3472

30
Result:- I have done threshold based segment

VIVA QUESTIONS:

DIGITAL IMAGE PROCESSING


LABORATORY INSTRUCTION SHEET

31
EXPERIMENT NO – 14
Experiment name: To perform 2-
diamensional discreat fourier transform
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika Sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-14
Aim: - To perform 2-diamensional discreat fourier transform
Apparatus: - MATLAB software
Program:-
32
clc; clearall; closeall;
I=imread('cameraman.tif');
I=im2double(I);
subplot(221);
imshow(I);
title('original image');
F=fft2(I);
subplot(222); imshow(abs(F));
title('Magnitude spectrum');
G= mat2gray(log10(1+abs(F)));
subplot(223); imshow(G);
title('log scaled magnitude spectrum');
I_recons= real(ifft2(F));
subplot(224);
imshow(I_recons);
title('Reconstructed image');

Output image

Result:- I have done 2-diamensional discreat fourier transform

VIVA QUESTIONS:

33
DIGITAL IMAGE PROCESSING
LABORATORY INSTRUCTION SHEET

EXPERIMENT NO – 15
Experiment name: To achive inverse of 2-D
DFT by using fftshift and ifftshift function .
Prepared by
(Dr. S.K. Agrawal) Assistant Professor,
(Mrs. Sarika Sharma) Lab Technician

Department of Electronics and Communication Engineering

MAHILA ENGINEERING COLLEGE AJMER


Nasirabad Road, Makhupura, Ajmer (305002)

Experiment-15
Aim: - To achive inverse of 2-D DFT by using fftshift and ifftshift function .
Apparatus: - MATLAB software
34
Program
clc; clearall; closeall;
I=imread('cameraman.tif');
I=im2double(I);
subplot(221);
imshow(I);
title('original image');
F=fftshift(fft2(I));
subplot(222); imshow(abs(F));
title('Magnitude spectrum');
G= mat2gray(log10(1+abs(F)));
subplot(223); imshow(G);
title('log scaled magnitude spectrum');
I_recons= ifft2(ifftshift(F));
subplot(224); imshow(I_ recons);
title('Reconstructed image');

Output image

Result:- I have achiveed inverse of 2-D DFT by using fftshift and ifftshift
function

VIVA QUESTIONS:

35

You might also like