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

Digital Image Processing Lab Manual-1 (1)

The document is a lab manual for the Digital Image Processing Lab at the Global Institute of Technology, Jaipur, detailing the lab plan for the Even Semester 2024-25. It includes a list of experiments, instructions for using MATLAB, and specific programming tasks related to image processing concepts such as histogram equalization, edge detection, and morphological operations. The manual emphasizes safety protocols and provides theoretical background for each experiment, along with expected outcomes and conclusions.

Uploaded by

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

Digital Image Processing Lab Manual-1 (1)

The document is a lab manual for the Digital Image Processing Lab at the Global Institute of Technology, Jaipur, detailing the lab plan for the Even Semester 2024-25. It includes a list of experiments, instructions for using MATLAB, and specific programming tasks related to image processing concepts such as histogram equalization, edge detection, and morphological operations. The manual emphasizes safety protocols and provides theoretical background for each experiment, along with expected outcomes and conclusions.

Uploaded by

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

GLOBAL INSTITUTE OF TECHNOLOGY

JAIPUR

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

DIGITAL IMAGE PROCESSING LAB


LAB MANUAL
Global Institute of Technology Jaipur, Rajasthan
LAB PLAN
Session : Even Semester 2024-25
Department of Computer Science & Engineering/ IT/ Artificial Intelligence and
Data Science
Subject Name:- Digital Image Processing Lab
Subject Code:- 6CS4-21
Faculty Name :- Kangana Saini & Shristi Arora

B. Tech. III Yr.- VI Sem- A, B, C & D

SNo List of Experiments

1 Introduction to MATLAB

2 To study the Image Processing concept.

3 To obtain histogram equalization image.

4 To Implement smoothing or averaging filter in spatial domain.

5 Program for opening and closing of the image.

6 To fill the region of interest for the image.

7 Program for morphological operation: erosion and dilation

8 Program of sharpen image using gradient mask.

9 Program for edge detection algorithm.

10 Program for DCT/IDCT computation.


DOs and DON’ Ts in Laboratory:

1. Do not handle any equipment before reading the instructions/Instruction manuals


2. Read carefully the power ratings of the equipment before it is switched on whether ratings
230 V/50Hz or 115V/60 Hz. For Indian equipments, the power ratings are normally 230 V/50Hz.
If you have equipment with 115/60 Hz ratings, do not insert power plug, as our normal supply is
230 V/50 Hz, which will damage the equipment.
3. Observe type of sockets of equipment power to avoid mechanical damage
4. Do not forcefully place connectors to avoid the damage
5. Strictly observe the instructions given by the teacher/Lab Instructor
EXPERIMENT NO. 1
EXPERIMENT TITLE:Introduction of MATLAB

AIM: Introduction of MATLAB

SOFTWARE USED
MATLAB

THEORY
MATLAB stands for MATrix LABoratory and the software is built up around vectors and matrices.
It is a technical computing environment for high performance numeric computation and visualization.
It integrates numerical analysis, matrix computation, signal processing and graphics in an easy-to-use
environment, where problems and solutions are expressed just as they are written mathematically,
without traditional programming. MATLAB is an interactive system whose basic data element is a
matrix that does not require dimensioning. It enables us to solve many numerical problems in a
fraction of the time that it would take to write a program and execute in a language such as
FORTRAN, BASIC, or C. It also features a family of application specific solutions, called toolboxes.
Areas in which toolboxes are available include signal processing, image processing, control systems
design, dynamic systems simulation, systems identification, neural networks, wavelength
communication and others. It can handle linear, non- linear, continuous-time, discrete- time,
multivariable and multirate systems.

How to start MATLAB


Choose the submenu "Programs" from the "Start" menu. From the "Programs" menu, open the
"MATLAB" submenu. From the "MATLAB" submenu, choose "MATLAB".

Procedure
1. Open Matlab.
2. File New Script.
3. Type the program in untitled window
4. File Save type filename.m in Matlab workspace path.
5. Debug Run.
6. Output will be displayed at Figure dialog box.

Library Functions

clc:
Clear command window
Clears the command window and homes the cursor.
clear all:
Removes all variables from the workspace.
close all:
Closes all the open figure windows.

exp:
Y = exp(X) returns the exponential ex for each element in array X.

linespace:
y = linspace(x1,x2) returns a row vector of 100 evenly spaced points between x1 and x2.
rand:
X = rand returns a single uniformly distributed random number in the interval (0,1).
ones:
X = ones(n) returns an n-by-n matrix of ones.

zeros:
X = zeros(n) returns an n-by-n matrix of zeros.

plot:
plot(X,Y) creates a 2-D line plot of the data in Y versus the corresponding values in X.

subplot:
subplot(m,n,p) divides the current figure into an m-by-n grid and creates an axes for a subplot in the
position specified by p.

stem:stem(Y) plots the data sequence, Y, as stems that extend from a baseline along the x-axis. The data
values are indicated by circles terminating each stem.
title:
title(str) adds the title consisting of a string, str, at the top and in the center of the current axes.

xlabel:
xlabel(str) labels the x-axis of the current axes with the text specified by str.

ylabel:
ylabel(str) labels the y-axis of the current axes with the string, str.

A Summary of MATLAB Commands Used

imread Read image from graphics file


imwrite Write image to graphics file
imfinfo Information about graphics file
imshow Display image
implay Play movies, videos, or image sequences
gray2ind Convert grayscale or binary image to indexed image
ind2gray Convert indexed image to grayscale image
mat2gray Convert matrix to grayscale image
rgb2gray Convert RGB image or colormap to grayscale
imbinarize Binarize image by thresholding
adapthresh Adaptive image threshold using local first-order statistics
otsuthresh Global histogram threshold using Otsu's method
im2uint16 Convert image to 16-bit unsigned integers
im2uint8 Convert image to 8-bit unsigned integers
imcrop Crop image
imresize Resize image
imrotate Rotate image
imadjust Adjust image intensity values or colormap
imcontrast Adjust Contrast tool
imsharpen Sharpen image using unsharp masking
histeq Enhance contrast using histogram equalization
adapthisteq Contrast-limited adaptive histogram equalization (CLAHE)
imhistmatch Adjust histogram of image to match N-bin histogram of reference image
imnoise Add noise to image
imfilter N-D filtering of multidimensional images
fspecial Create predefined 2-D filter
weiner2 2-D adaptive noise-removal filtering
medfilt2 2-D median filtering
ordfilt2 2-D order-statistic filtering
imfill Fill image regions and holes
imclose Morphologically close image
imdilate Dilate image
imerode Erode image
imopen Morphologically open image
imreconstruct Morphological reconstruction
watershed Watershed transform
dct2 2-D discrete cosine transform
hough Hough transform
graydist Gray-weighted distance transform of grayscale image
fft2 2-D fast Fourier transform
ifftshift Inverse FFT shift
imcomplement Complement image
immultiply Multiply two images or multiply image by constant
imsubtract Subtract one image from another or subtract constant from image
imdivide Divide one image into another or divide image by constant
imadd Add two images or add constant to image

.
EXPERIMENT NO. 2
EXPERIMENT TITLE: Image Processing concept
AIM: To study the Image Processing concept.

TOOLS REQUIRED: MATLAB

THEORY: Digital images play an important role both in daily life applications as well as in the
areas of research technology. The digital image processing refers to the manipulation of an
image by means of processor. The different elements of an image processing system include
image acquisition, image storage, image processing and display
An image is two dimensional function that represent a message of sum characteristics such as
brightness or color of viewed scene in the first mat lab program the command used from mat
lab is imcomplement

PROGRAM:
% Program to study the image processing concept
I=imread('pout.tif');
J=imcomplement(I);
figure,imshow(I)
figure,imshow(J)
K=imadjust(I,[0;0.4],[0.5;1])
figure,imshow(K)

Result:

Original Image
Complement Image

Conclusion: Thus we have studied the how to obtain complement image from the original
image.

EXPERIMENT NO. 3
EXPERIMENT TITLE: Histogram equalization image
AIM: To obtain histogram equalization image.

TOOLS REQUIRED: MATLAB

THEORY: Histogram equalization is a method in image processing of contrast adjustment


using the image's histogram. Histogram equalization often produces unrealistic effects in
photographs; however it is very useful for scientific images like thermal or x-ray images,
often the same class of images to which one would apply false color. Also histogram
equalization can produce undesirable effects when applied to images with low color depth.
For example, if applied to 8-bit image displayed with 8 bit gray scale it will further
reduce color depth (number of unique shades of gray) of the image. Histogram equalization
will work the best when applied to images with much higher depth than palette size,
like continuous data or 16-bit gray-scale images.

PROGRAM:
% Program to obtain histogram equalization concept

I=imread('trees.tif');
J=imcomplement(I);
imhist(J,100);
imshow(I);
title('original');
figure,imshow(J);
title('complement');
I=histeq(I);
figure,imhist(I,64);
title('equilized');
figure,imhist(J,64);
title('histogram');
n=numel(I);
p=imhist(I)/n;
figure,plot(p);
title('normalized');
K=imadjust(I,[0;1],[0.4;1],0.5);
figure,imshow(K);
title('adjusted image');
T=maketform('affine',[.3 0 0;.5 1 0;0 1 1]);
tformfwd([0,0],T);
I2=imtransform(I,T);
figure,imshow(I2);
title('forward image');

Result:

Original Histogram

Equalized Histogram

Conclusion: Thus we have obtained the Equalized Histogram from the original Histogram.
EXPERIMENT NO. 4
EXPERIMENT TITLE: Averaging filter in spatial domain
AIM: To Implement smoothing or averaging filter in spatial domain.

TOOLS REQUIRED: MATLAB

THEORY: Filtering is a technique for modifying or enhancing an image. ... Mask


or filters will be defined. The general process of convolution and correlation will be
introduced via an example. Also smoothing linear filters such as box and weighted average
filters will be introduced.
In statistic and image processing, to smooth a data set is to create an
approximating function that attempts to capture important patterns in the data, while
leaving out noise or other fine-scale structures/rapid phenomena. In smoothing, the data
points of a signal are modified so individual points (presumably because of noise) are
reduced, and points that are lower than the adjacent points are increased leading to a
smoother signal. Smoothing may be used in two important ways that can aid in data
analysis by being able to extract more information from the data as long as the assumption
of smoothing is reasonable by being able to provide analyses that are both flexible and
Robust different algorithms are used in smoothing.

PROGRAM:
% Program for implementation of smoothing or averaging filter in spatial domain

I=imread('trees.tif');
subplot(2,2,1);
imshow(J);
title('original image');
f=ones(3,3)/9;
h=imfilter(I,f,'circular');
subplot(2,2,2);
imshow(h);
title('averaged image');

Result:
Conclusion: Thus we have performed the smoothing or averaging filter operation on the
Original image and we get filtered image.

EXPERIMENT NO. 5
EXPERIMENT TITLE: Opening and Closing of the image
AIM: Program for opening and closing of the image.

TOOLS REQUIRED: MATLAB

THEORY: In mathematical morphology, opening is the dilation of the erosion of


a set by a structuring elements B:
Together with closing, the opening serves in computer vision and image processing as a
basic workhorse of morphological noise removal. Opening removes small objects from the
foreground (usually taken as the bright pixels) of an image, placing them in the
background, while closing removes small holes in the foreground, changing small islands of
background into foreground. These techniques can also be used to find specific shapes in
an image. Opening can be used to find things into which a specific structuring element can
fit (edges, corners, ...).
In mathematical morphology, the closing of a set (binary image) A by a structuring
element B is the erosion of the dilation of that set. In image processing, closing is, together
with opening, the basic workhorse of morphological image removal. Opening removes
small objects, while closing removes small holes.

PROGRAM:
f=imread('coins.png');
se=strel('square',20);
fo=imopen(f,se);
figure,imshow(f)
title('input image');
figure,imshow(fo)
title('opening of input image');
fc=imclose(f,se);
figure,imshow(fc)
title('opening of input image');
foc=imclose(fo,se);
figure,imshow(foc)
title('closing of opened input image');

Result:
Conclusion: Thus we have obtained the opened image and closed image from the original
Image.

EXPERIMENT NO. 6
EXPERIMENT TITLE: Region of Interest for the image
AIM: To fill the region of interest for the image.

TOOLS REQUIRED: MATLAB

THEORY: A region of interest (often abbreviated ROI), are samples within a data set
identified for a particular purpose. The concept of a ROI is commonly used in many
application areas. For example, in medical imaging, the boundaries of a tumor may be
defined on an image or in a volume, for the purpose of measuring its size. The endo cardial
border may be defined on an image, perhaps during different phases of the cardiac cycle,
for example, end-systole and end-diastole, for the purpose of assessing cardiac function.
In geographical information systems(GIS), a ROI can be taken literally as a polygonal
selection from a 2D map. In computer vision and optical character recognition, the ROI
defines the borders of an object under consideration. In many applications, symbolic
(textual) labels are added to a ROI, to describe its content in a compact manner. Within a
ROI may lie individual points of interest (POIs).

PROGRAM:
% Program for ROI
clc;
close all;
load trees
I=ind2gray(X,map);
imshow(I)
title('original image');
I2=roifill;
imshow(I2)
title('OUTPUT IMAGE');

Result:

Original Image
Output image

Conclusion: Thus we have filled the interested region in the original image.

EXPERIMENT NO. 7
EXPERIMENT TITLE: Edge detection algorithm
AIM: Program for edge detection algorithm.

TOOLS REQUIRED: MATLAB

THEORY: The Canny edge detector is an edge detection operator that uses a multi
stage algorithm to detect a wide range of edges in images. It was developed by John F.
Canny in 1986. Canny also produced a computational theory of edge detection explaining
why the technique works.

The Process of Canny edge detection algorithm can be broken down to 5 different steps:
1. Apply Gaussian filter to smooth the image in order to remove the noise
2. Find the intensity gradients of the image
3. Apply non-maximum suppression to get rid of spurious response to edge detection
4. Apply double threshold to determine potential edges
5. Track edges by hypothesis: Finalize the detection of edges by suppressing all the
other edges that are weak and not connected to strong edges.

PROGRAM:
%Program for edge detection algorithm

I=imread('coins.png');
figure,imshow(I)
title ('figure 1 original image');
h=ones(5,5)/25;
b=imfilter(I,h);
figure,imshow(b)
title ('figure 2 filtered image');
c=edge(b,'sobel');
figure,imshow(c)
title ('figure 3 edge detected output by sobel operator');
d=edge(b,'prewitt');
figure,imshow(d)
title ('figure 4 edge detected output by prewitt operator');
e=edge(b,'robert');
figure,imshow(e)
title ('figure 5 edge detected output by robert operator');
f=edge(b,'canny');
figure,imshow(f)title ('figure 6 edge detected output by canny operator');

Result:

Edge detected image Edge detected image


Conclusion: Thus we have detected the edges in the original image.

EXPERIMENT NO. 8
EXPERIMENT TITLE: Sharpen image using gradient mask
AIM: Program of sharpen image using gradient mask.

TOOLS REQUIRED: MATLAB


THEORY: An image gradient is a directional change in the intensity or color in an image.
The gradient of the image is one of the fundamental building blocks in image processing.
For example the Canny edge detector uses image gradient for edge detection.
Mathematically, the gradient of a two-variable function (here the image intensity function)
at each image point is a 2D vector with the components given by the derivatives in the
horizontal and vertical directions. At each image point, the gradient vector points in the
direction of largest possible intensity increase, and the length of the gradient vector
corresponds to the rate of change in that direction.
PROGRAM:
% Program of sharpen image using gradient mask
I=imread('coins.png');
subplot(2,2,1);
imshow(I)
title('Original Image');
h=fspecial('sobel');
f=imfilter(I,h,'replicate');
subplot(2,2,2);
imshow(F)
title('filtered image by sobel mask');
s=I+F;
subplot(2,2,4);
imshow(s)
title('Final o/p Image');

Result:
Original Image

Conclusion: Thus we have perform the sharpening operation using gradient mask on the
Original image.

EXPERIMENT NO. 9
EXPERIMENT TITLE: Erosion and Dilation
AIM: Program for morphological operation: erosion and dilation.

TOOLS REQUIRED: MATLAB

THEORY: Erosion (usually represented by ⊖ ) is one of two fundamental operations (the


other being dilation) in morphological image processing from which all other
morphological operations are based. It was originally defined for binary images, later being
extended to grayscale images, and subsequently to complete lattices.

With A and B as two sets in Z2 (2D integer space), the dilation of A and B is defined as
A(+)B={Z|(B )Z∩A ≠ ɸ}

In the above example, A is the image while B is called a structuring element.

In the equation,(B )Z simply means ta king the reflections of B about its origin and shifting it
by Z. Hence dilation of A with

B is a set of all displacements, Z, such that (B )Z and A overlap by at least one element.
Flipping of B about the origin and then moving it past image A is analogous to the
convolution process. In practice flipping of B is not done always.

Dilation adds pixels to the boundaries of object in an image. The number of pixels added
depends on the size and shape of the structuring element. Based on this definition, dilation
can be defined as

A(+)B={{Z|(B )Z∩A} ϵ A}

PROGRAM:
% Program for morphological operations: Erosions & Dilation

f=imread('coins.png');
B=[0 1 1;1 1 1;0 1 0];
f1=imdilate(f,B);
se=strel('disk',10);
f2=imerode(f,se);
figure,imshow(f)
title('input image');
figure,imshow(f1)title('delated image');
figure,imshow(f2)
title('eroded image');
Result:

Erroded Image

Dilated Image

Conclusion: Thus we have obtained the eroded and dilated image for the original image
EXPERIMENT NO. 10
EXPERIMENT TITLE: DCT/IDCT computation
AIM: Program for DCT/IDCT computation.

TOOLS REQUIRED: MATLAB

THEORY: A discrete cosine transform (DCT) expresses a finite sequence of data points in
terms of a sum of cosine functions oscillating at different frequencies. DCTs are important
to numerous applications in science and engineering, from lossy
compression of audio (e.g. MP3) and images (e.g. JPEG) (where small high-frequency
components can be discarded), to spectral methods for the numerical solution of partial
differential equations. The use of cosine rather than sine functions is critical for
compression, since it turns out (as described below) that fewer cosine functions are needed
to approximate a typical signal, whereas for differential equations the cosines express a
particular choice of boundary conditions.

In particular, a DCT is a Fourier-related transform similar to the discrete Fourier


transform (DFT), but using only real numbers. The DCTs are generally related to Fourier
Series coefficients of a periodically and symmetrically extended sequence whereas DFTs
are related to Fourier Series coefficients of a periodically extended sequence. DCTs are
equivalent to DFTs of roughly twice the length, operating on real data with even symmetry
(since the Fourier transform of a real and even function is real and even), whereas in some
variants the input and/or output data are shifted by half a sample. There are eight standard
DCT variants, of which four are common.

Like for the DFT, the normalization factor in front of these transform definitions is merely a
convention and differs between treatments. For example, some authors multiply the
transforms by so that the inverse does not require any additional multiplicative factor.
Combined with appropriate factors of √(2/N), this can be used to make the transform
matrix orthogonal.

PROGRAM:
clc;
clear all;
close all;
m=input('Enter the basis matrix
dimension: ');
% Request user input
n=m;
alpha2=ones(1,n)*sqrt(2/n);
alpha2(1)=sqrt(1/n);
alpha1=ones(1,m)*sqrt(2/m);
alpha(1)=sqrt(1/m); % square root.
for u=0:m-1for v=0:n-1
for x=0:m-1
for y=0:n-1
a{u+1,v+1}(x+1,y+1)=alpha1(u+1)*alpha2(v+1)*...
cos((2*x+1)*u*pi/(2*n))*cos((2*y+1)*v*pi/(2*n));
end
end
end
end
mag=a;
figure(3)
% Create figure graphics object
k=1;
% Code to plot the basis
for i=1:m
for j=1:n
subplot(m,n,k)
imshow(mag{i,j},256)
k=k+1;
end
end
Enter the basis matrix dimension: 5

Result:

Conclusion: Thus we have obtained the DCT/IDCT for the image.

You might also like