0% found this document useful (0 votes)
47 views35 pages

Lab Manual DIP 6CS4-21

Uploaded by

Nishka Sharma
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)
47 views35 pages

Lab Manual DIP 6CS4-21

Uploaded by

Nishka Sharma
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

Techno India NJR Institute of Technology

Department of Computer Science and Engineering

B.Tech. VI Semester

Lab: Digital Image Processing Lab (6CS4-21)


Session 2022-23

Dr. Vivek Jain


(Associate Professor)
Department of ECE
CO.NO. Cognitive Level Course Outcome
1 Comprehension Able to generate different Continuous and Discrete time signals.
Develop image enhancement, compression and edge detection
2 Application
using MATLAB.
Design and Develop IIR & FIR Filter using different
3 Analysis
approximation methods using MATLAB.
4 Synthesis Implement algorithms for image processing on DSP Processor.
5 Evaluation Evaluate the signal to noise ration of the image.

Course
PO PO PO
Outcom PO1 PO3 PO5 PO6 PO8 PO9 PO10 PO11 PO12
2 4 7
e
CO1 2 1 1 1 2 0 0 0 0 0 0 0
CO2 2 2 2 1 2 0 0 0 0 0 0 0
CO3 1 2 2 1 2 0 0 0 0 0 0 0
CO4 2 2 2 1 2 0 0 0 0 0 0 0
CO5 2 1 2 1 2 1 0 0 0 0 0 0
C36402
2.25 1.75 2.25 1.00 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
(AVG)
Experiments List:

Experiment 1: Write MATLAB code for add two Images.


Experiment 2: Write the MATLAB code for plot the histogram of gray image.
Experiment 3: Write the MATLAB code for plot the histogram of colour image.
Experiment 4: Write the MATLAB code for plot the multiple thresholding of colour
image.
Experiment5: Write the MATLAB code for plot the equalization of colour image.
Experiment 6: Write the MATLAB code for plot the extraction of colour image.
Experiment 7: Write the MATLAB code for rotation of image.
Experiment 8: Write the MATLAB code for scaling the intensity level of image.
Experiment 9:Write the MATLAB code for plot the single thresholding of colour image.
Experiment 10:Write the MATLAB code for 2 D Fourier transform image.
Experiment 11:Write the MATLAB code for linear convolution.
Experiment 12:Write the MATLAB code for highly selectively Filter.
Experiment 13:Write the MATLAB Code for Edge Detection of Image.
Experiment 14:Write the MATLAB Code for Morphological operation on Image.
1. Write MATLAB code for add two Images.

MATLAB CODE:

J=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');


size(J);
J=imresize(J,[256,256])
I=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\saturn1.png');
size(I);
I=imresize(I,[256,256])
K=I+J;
figure;
subplot(2,2,1);subimage(J);title('cameraman.tif ');
subplot(2,2,2);subimage(I);title('saturn.png ');
subplot(2,2,3);subimage(K);title('Finalimage');

Result or Output
2. Write the MATLAB code for plot the histogram of gray image.

MATLAB CODE:

clear all; clc; close all;

img=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

img=rgb2gray(img);

[rows cols]=size(img);

hist(1:256)=0;

for i=1:rows

for j=1:cols

k=img(i,j)+1;

hist(k)=hist(k)+1;

end

end

subplot(2,1,1);imshow(img);title('Gray Image ');

subplot(2,1,2);plot(hist);title('Histogram ');

grid on ;

% figure;

% bar(hist);

Result or Output
3. Write the MATLAB code for plot the histogram of colour image.

MATLAB CODE:

clear all; clc; close all;

img=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

[rows cols bnd]=size(img);

hist1(1:256)=0;

hist2(1:256)=0;

hist3(1:256)=0;

for i=1:rows

for j=1:cols

k=img(i,j,1)+1;

hist1(k)=hist1(k)+1;

l=img(i,j,2)+1;

hist2(l)=hist2(l)+1;

m=img(i,j,3)+1;

hist3(m)=hist3(m)+1;

end

end

subplot(4,1,1);imshow(img);title('Gray Image ');

subplot(4,1,2);plot(hist1,'r'); title('Histogram of red colour ');

hold on;

subplot(4,1,3);plot(hist2,'g'); title('Histogram of green colour ');

subplot(4,1,4);plot(hist3,'b');title('Histogram of blue colour ');

hold off;
Result or Output
4. Write the MATLAB code for plot the multiple thresholding of colour image.

MATLAB CODE:

close all; clear all; clc;


img=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');
img=rgb2gray(img);
img=imresize(img,[256 256]);
[rows cols]=size(img);
hist(1:256)=0;
for i=1:rows
for j=1:cols
k=img(i,j)+1;
hist(k)=hist(k)+1;
end
end
th1=20;
th2=60;
th3=100;
th4=180;
th5=205;
th6=220;
for i=1:rows
for j=1:cols
if(img(i,j)<=th1)
img1(i,j)=0;
elseif(img(i,j)>th1 && img(i,j)<=th2)
img2(i,j)=60;
elseif(img(i,j)>th2 && img(i,j)<=th3)
img1(i,j)=100;
elseif(img(i,j)>th3 && img(i,j)<=th4)
img1(i,j)=150;
elseif(img(i,j)>th4 && img(i,j)<=th5)
img1(i,j)=175;
elseif(img(i,j)>th5 && img(i,j)<=th6)
img1(i,j)=220;
elseif(img(i,j)>th6)
img1(i,j)=255;
end
end
end
subplot(3,1,1);imshow(img);title('Image');
subplot(3,1,2);imshow(uint8(img1));title('Modified Image');
subplot(3,1,3); plot(hist);title('Histogram of Image');
Result or Output
5. Write the MATLAB code for plot the equalization of colour image.

MATLAB CODE:

close all;clear all;clc;


img=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');
[r,c]=size(img);
figure;
subplot(3,1,1);imshow(img);title('Image');

hist(1:256)=0;
for i=1:r
for j=1:c
k=img(i,j)+1;
hist(k)=hist(k)+1;

end
end
subplot(3,1,2);plot(hist,'r');title('Histrogram of Red Colour');

for k=2:256
hist(k)=hist(k)+hist(k-1); %Running Sum

end
subplot(3,1,3);plot(hist,'r'); title('Histrogram of Red Colour after Equlaization');
Result or Output
6. Write the MATLAB code for plot the extraction of colour image.

MATLAB CODE:
clear all; close all; clc
A=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');
% A=rgb2gray(A);
% A=imread('cameraman.tif');
b1=double(bitget(A,8));
b2=double(bitget(A,7));
b3=double(bitget(A,6));
b4=double(bitget(A,5));
b5=double(bitget(A,4));
b6=double(bitget(A,3));
b7=double(bitget(A,2));
b8=double(bitget(A,1));
subplot(3,3,1);imshow(uint8(A));title('Original Image');
subplot(3,3,2);imshow((b1));title('Bit1(Msb) Image');
subplot(3,3,3);imshow((b2));title('Bit2 Image');
subplot(3,3,4);imshow((b3));title('Bit3 Image');
subplot(3,3,5);imshow((b4));title('Bit4 Image');
subplot(3,3,6);imshow((b5));title('Bit5 Image');
subplot(3,3,7);imshow((b6));title('Bit6 Image');
subplot(3,3,8);imshow((b7));title('Bit7 Image');
subplot(3,3,9);imshow((b8));title('Bit8{Lsb) Image');
Result or Output
7. Write the MATLAB code for rotation of image.

MATLAB CODE:

I=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

subplot(4,1,1);imshow(I)

title('Original Image')

J = imrotate(I,90,'bilinear','crop');

subplot(4,1,2);imshow(J)

title(' Image Rotate by 90 degree')

K = imrotate(I,180,'bilinear','crop');

subplot(4,1,3);imshow(K)

title(' Image Rotate by 90 degree')

L = imrotate(I,270,'bilinear','crop');

subplot(4,1,4);imshow(L)

title(' Image Rotate by 270 degree')

Result or Output
8. Write the MATLAB code for scaling the intensity level of image.

MATLAB CODE:

I=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

J = imadjust(I,[.2 .3 0; .6 .7 1],[]);

K=rgb2gray(I)

subplot(1,3,1);imshow(I);title('Original Color Image')

subplot(1,3,2);imshow(J);title('Modified Image')

subplot(1,3,3);imshow(K);title('Gray Image')

Result or Output
9. Write the MATLAB code for plot the single thresholding of colour image.

MATLAB CODE:

i=imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

n=size(i);

th1=127;

for k=1:n(1)

for l=1:n(2)

if(i(k,l)<th1)

j(k,l)=0;

else

j(k,l)=255;

end

end

end

subplot(1,2,1);

imshow(i);

title('Original Color Image')

subplot(1,2,2);

imshow(uint8(j));

title('Modified Image')

Result or Output
10 Write the MATLAB code for 2 D Fourier transform image.

MATLAB CODE:

P = peaks(20);

X = repmat(P,[5 10]);

subplot(3,1,1);imagesc(X)

Y = fft2(X);

subplot(3,1,2);imagesc(abs(fftshift(Y)))

Z = fft2(X,2^nextpow2(100),2^nextpow2(200));

subplot(3,1,3);imagesc(abs(fftshift(Z)));

Result or Output
11 Write the MATLAB code for linear convolution.

MATLAB CODE:

x1=1:5;

x2=1:5;

y1=1:5;

y2=1:5;

x=(min(x1)+min(x2)):max((x1)+max(x2));

y=conv(y1,y2);

subplot(3,1,1); stem(x1,y1) ;title('First Input Sequence')

subplot(3,1,2); stem(x2,y2);title('Second Input Sequence')

subplot(3,1,3); stem(x,y);title('Output Sequence')

Result or Output
12 Write the MATLAB code for highly selectively Filter.

MATLAB CODE:

%FIR Bandpass Filter

%Design a 48th-order FIR bandpass filter with passband

%0.35????0.65? rad/sample. Visualize its magnitude and phase responses.

b = fir1(48,[0.35 0.65]);

figure

freqz(b,1,512)

title('Response of FIR Bandpass Filter ')

%FIR Highpass Filter

%Load chirp.mat. The file contains a signal, y, that has most of its power above Fs/4,

%or half the Nyquist frequency. The sample rate is 8192 Hz.

%Design a 34th-order FIR highpass filter to attenuate the components of the

%signal below Fs/4. Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB

%of ripple.

load chirp

t = (0:length(y)-1)/Fs;

bhi = fir1(34,0.48,'high',chebwin(35,30));

figure

freqz(bhi,1)

title('Response of FIR Highpass Filter 1')

figure

freqz(b,1,512)

title('Response of FIR Highpass Filter 2 ')


Result or Output
13 Write the MATLAB Code for Edge Detection of Image.

MATLAB CODE:

% importing the image

I = rgb2gray(imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp'));

subplot(2, 4, 1),

imshow(I);

title('Gray Scale Image');

% Sobel Edge Detection

J = edge(I, 'Sobel');

subplot(2, 4, 2),

imshow(J);

title('Sobel');

% Prewitt Edge detection

K = edge(I, 'Prewitt');

subplot(2, 4, 3),

imshow(K);

title('Prewitt');

% Robert Edge Detection

L = edge(I, 'Roberts');

subplot(2, 4, 4),

imshow(L);

title('Robert')

% Log Edge Detection


M = edge(I, 'log');

subplot(2, 4, 5),

imshow(M);

title('Log')

% Zerocross Edge Detection

M = edge(I, 'zerocross');

subplot(2, 4, 6),

imshow(M);

title('Zerocross')

% Canny Edge Detection

N = edge(I, 'Canny');

subplot(2, 4, 7),

imshow(N);

title('Canny')

Result or Output
14 Write the MATLAB Code for Morphological operation on Image.

MATLAB CODE:

I = imread('C:\Users\VLSI LAB\Desktop\Lab File\image\lenacolor.bmp');

subplot(2, 3, 1),

imshow(I);

title('Original image')

% Dilated Image

se = strel('line', 7, 7);

dilate = imdilate(I, se);

subplot(2, 3, 2),

imshow(dilate);

title('Dilated image')

% Eroded image

erode = imerode(I, se);

subplot(2, 3, 3),

imshow(erode);

title('Eroded image')

% Opened image

open = imopen(I, se);

subplot(2, 3, 4),

imshow(open);

title('Opened image');

% Closed image

close = imclose(I, se);


subplot(2, 3, 5),

imshow(close);

title('Closed image');

Result or Output
TECHNO INDIA NJR INSTITUTE OF TECHNOLOGY UDAIPUR
Computer Science and Engineering
B. TECH III– YEAR (VI Sem)
SUBJECT 6CS301

Digital Image Processing

VIVA
Q 1. Define Image?

Q 2. Define Image Sampling?

Q 3. Define Quantization ?

Q4. Define Mach Band Effect?

Q5.Define Brightness?

Q6. Define Tapered Quantization?

Q7. What Do You Meant By Gray Level?

Q8. Define Resolutions?

Q9. Write The M X N Digital Image In Compact Matrix Form?

Q10. Write The Expression To Find The Number Of Bits To Store A Digital
Image?

Q11. What Do You Meant By Zooming Of Digital Images?

Q12. What Do You Meant By Shrinking Of Digital Images?

Q13. Define The Term Radiance?

Q14. Define The Term Luminance?

Q15. What Is Image Transform?

Q16. What Are The Applications Of Transform?

Q17. Give The Conditions For Perfect Transform?

Q18. What Are The Properties Of Unitary Transform?


Q19. Write The Expression Of One-dimensional Discrete Fourier Transforms?

Q20. Properties Of Twiddle Factor?

Q21. Give The Properties Of One-dimensional DFT?

Q22. Give The Properties Of Two-dimensional DFT?

Q23. What Is Cosine Transform?

Q24. Write The Properties Of Cosine Transform?

Q25. Write The Properties Of Sine Transform?

Q26. Write The Properties Of Hadamard Transform?

Q27. Explain The Term Digital Image?

Q28. Explain The Term Digital Image?

Q29. Write Any Four Applications Of DIP?

Q30. What Is The Effect Of Mach Band Pattern?

Q31. Write Down The Properties Of 2d Fourier Transform?

Q32. What Is Image Enhancement?

Q33. Name The Categories Of Image Enhancement And Explain?

Q34. What Do You Mean By Point Processing?

Q35. What Is Image Negatives?

Q36. Define Histogram?

Q37. Define Derivative Filter?

Q38. Explain Spatial Filtering?

Q39. Define Averaging Filters?

Q40. What Is A Median Filter?

Q41. What Is Maximum Filter And Minimum Filter?

Q42. What Is A Adaptive Filter?


Q43. What role does the compression play in image processing?

Q44. What are the two types of image compression?

Q45. What is image compression algorithm?


TECHNO INDIA NJR INSTITUTE OF TECHNOLOGY UDAIPUR
Computer Science and Engineering
B. TECH III– YEAR (VI Sem)
SUBJECT 6CS301

Digital Image Processing

Quiz
1.What is Digital Image Processing?
a) It’s an application that alters digital videos
b) It’s a software that allows altering digital pictures
c) It’s a system that manipulates digital medias
d) It’s a machine that allows altering digital images
2. Which of the following process helps in Image enhancement?
a) Digital Image Processing
b) Analog Image Processing
c) Both a and b
d) None of the above
3. Among the following, functions that can be performed by digital image
processing is?
a) Fast image storage and retrieval
b) Controlled viewing
c) Image reformatting
d) All of the above
4. Which of the following is an example of Digital Image Processing?
a) Computer Graphics
b) Pixels
c) Camera Mechanism
d) All of the mentioned
5. What are the categories of digital image processing?
a) Image Enhancement
b) Image Classification and Analysis
c) Image Transformation
d) All of the mentioned
6. How does picture formation in the eye vary from image formation in a
camera?
a) Fixed focal length
b) Varying distance between lens and imaging plane
c) No difference
d) Variable focal length
7. What are the names of the various colour image processing categories?
a) Pseudo-color and Multi-color processing
b) Half-color and pseudo-color processing
c) Full-color and pseudo-color processing
d) Half-color and full-color processing

8. Which characteristics are taken together in chromaticity?


a) Hue and Saturation
b) Hue and Brightness
c) Saturation, Hue, and Brightness
d) Saturation and Brightness

9. Which of the following statement describe the term pixel depth?


a) It is the number of units used to represent each pixel in RGB space
b) It is the number of mm used to represent each pixel in RGB space
c) It is the number of bytes used to represent each pixel in RGB space
d) It is the number of bits used to represent each pixel in RGB space
10. The aliasing effect on an image can be reduced using which of the
following methods?
a) By reducing the high-frequency components of image by clarifying the
image
b) By increasing the high-frequency components of image by clarifying the
image
c) By increasing the high-frequency components of image by blurring the
image
d) By reducing the high-frequency components of image by blurring the
image

11.Which of the following is the first and foremost step in Image Processing?
a) Image acquisition
b) Segmentation
c) Image enhancement
d) Image restoration

12.Which of the following image processing approaches is the fastest, most


accurate, and flexible?
a) Photographic
b) Electronic
c) Digital
d) Optical

13.Which of the following is the next step in image processing after


compression?
a) Representation and description
b) Morphological processing
c) Segmentation
d) Wavelets

14. ___________ determines the quality of a digital image.


a) The discrete gray levels
b) The number of samples
c) discrete gray levels & number of samples
d) None of the mentioned

15.Image processing involves how many steps?


a) 7
b) 8
c) 13
d) 10

16.Which of the following is the abbreviation of JPEG?


a) Joint Photographic Experts Group
b) Joint Photographs Expansion Group
c) Joint Photographic Expanded Group
d) Joint Photographic Expansion Group

17.Which of the following is the role played by segmentation in image


processing?
a) Deals with property in which images are subdivided successively into
smaller regions
b) Deals with partitioning an image into its constituent parts or objects
c) Deals with extracting attributes that result in some quantitative
information of interest
d) Deals with techniques for reducing the storage required saving an image,
or the bandwidth required transmitting it

18.The digitization process, in which the digital image comprises M rows and N
columns, necessitates choices for M, N, and the number of grey levels per
pixel, L. M and N must have which of the following values?
a) M have to be positive and N have to be negative integer
b) M have to be negative and N have to be positive integer
c) M and N have to be negative integer
d) M and N have to be positive integer

19.Which of the following tool is used in tasks such as zooming, shrinking,


rotating, etc.?
a) Filters
b) Sampling
c) Interpolation
d) None of the Mentioned

20. The effect caused by the use of an insufficient number of intensity levels in
smooth areas of a digital image _____________
a) False Contouring
b) Interpolation
c) Gaussian smooth
d) Contouring

21.What is the procedure done on a digital image to alter the values of its
individual pixels known as?
a) Geometric Spacial Transformation
b) Single Pixel Operation
c) Image Registration
d) Neighbourhood Operations

22.Points whose locations are known exactly in the input and reference images
are used in Geometric Spacial Transformation.
a) Known points
b) Key-points
c) Réseau points
d) Tie points

23.___________ is a commercial use of Image Subtraction.


a) MRI scan
b) CT scan
c) Mask mode radiography
d) None of the Mentioned

24.Approaches to image processing that work directly on the pixels of incoming


image work in ____________
a) Spatial domain
b) Inverse transformation
c) Transform domain
d) None of the Mentioned
25. Which of the following in an image can be removed by using a smoothing
filter?
a) Sharp transitions of brightness levels
b) Sharp transitions of gray levels
c) Smooth transitions of gray levels
d) Smooth transitions of brightness levels

26.Region of Interest (ROI) operations is generally known as _______


a) Masking
b) Dilation
c) Shading correction
d) None of the Mentioned

27.Which of the following comes under the application of image blurring?


a) Image segmentation
b) Object motion
c) Object detection
d) Gross representation

28. Which of the following filter’s responses is based on the pixels ranking?
a) Sharpening filters
b) Nonlinear smoothing filters
c) Geometric mean filter
d) Linear smoothing filters

29.Which of the following illustrates three main types of image enhancing


functions?
a) Linear, logarithmic and power law
b) Linear, logarithmic and inverse law
c) Linear, exponential and inverse law
d) Power law, logarithmic and inverse law

30. Which of the following is the primary objective of sharpening of an image?


a) Decrease the brightness of the image
b) Increase the brightness of the image
c) Highlight fine details in the image
d) Blurring the image

30.Which of the following operation is done on the pixels in sharpening the image,
in the spatial domain?
a) Differentiation
b) Median
c) Integration
d) Average

QUIZ ANSWER KEY

Q1. B Q2. C Q3. D Q4. D Q5. D Q6 D Q7. C Q8. A Q9. D Q10. D Q11. A Q12. C Q13. B
Q14. C Q15. D Q16. A Q17. B Q18. D Q19. C Q20. A Q21. B Q22. D Q23. C Q24. A Q25 B
Q26. A Q27. D Q28. B Q29. D Q30. C

You might also like