Laboratory Manual: Faculty of Engineering and Technology Bachelor of Technology
Laboratory Manual: Faculty of Engineering and Technology Bachelor of Technology
BACHELOR OF TECHNOLOGY
Image Processing
(203105471)
7th SEMESTER
COMPUTER SCIENCE ENGINEERING DEPARTMENT
Laboratory Manual
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
IMAGE PROCESSING
PRACTICAL BOOK
COMPUTER SCIENCE AND ENGINEERING DEPARTMENT
PREFACE
It gives us immense pleasure to present the first edition of Image Processing Practical Book
for the B. Tech., 4th year students of PARUL UNIVERSITY.
The Image Processing theory and laboratory course at PARUL UNIVERSITY,
WAGHODIA, VADODARA is designed in such a way that students will have basic
understanding of the subject in the theory classes and then they have to try their hands in the
experiments session to realize problems learned during the theoretical sessions. The main
objective of the Image Processing laboratory course is: Learning Image Processing
through Experimentation. All the experiments are designed to understand and explore Image
Processing in order to render the student’s various approaches used to processing and
improving the quality of the images. Further, it will give exposure to students when to use
the specific algorithms for a given applications.
The objective of Image Processing Practical Book is to provide a comprehensive source for
all the experiments included in the Image Processing laboratory course. It also explains all
the aspects related to every experiment such as: understanding of basics of algorithms, how
to write program in MATLAB for image processing in order to make them understand the
fundamentals of Image Processing.
We acknowledge the authors and publishers of all the books which we have consulted while
developing this Practical book. Hopefully this Image Processing Practical Book will serve
the purpose for which it has been developed.
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
INSTRUCTIONS TO STUDENTS
1. Be prompt in arriving to the laboratory and always come well prepared for the experiment.
2. Be careful while working on the equipment operated with high voltage power supply.
3. Work quietly and carefully. Give equal opportunity to all your fellow students to work
on the instruments.
4. Every student should have his/her individual copy of the Image Processing Practical
Book.
5. Every student has to prepare the notebooks specifically reserved for the Image
Processing
Practical work ― Image Processing Practical Book‖.
6. Every student has to necessarily bring his/her Image Processing Practical Book, Practical
record Notebook, when he/she comes to the practical to perform the experiment.
7. All the algorithms/ codes/ observations have to be neatly recorded in the Image
Processing Practical Class Notebook (as explained in the Image Processing Practical
Book) and get it verified by the instructor before leaving the laboratory.
8. Do not share your programs with your fellow student. Every student has to render his/her
own set of results by performing the experiment separately.
9. Do not forget to get the information of your next allotment (the experiment which is to be
performed by you in the next laboratory session) before leaving the laboratory from the
Technical Assistant.
10.The grades for the Image Processing Practical course work will be awarded based on your
performance in the laboratory, regularity, recording of experiments in the Image Processing Practical
Final Notebook, lab quiz, regular viva-voce and end-term examination.
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
CERTIFICATE
Head of Department:...........................................
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
TABLE OF CONTENT
Sr. Page No Date of Date of Marks
Experiment Title Sign
No. Start Completion (out of 10)
From To
To study and implement basic
commands of MATLAB required
1 for digital image processing
technique, and
various image file formats.
To study the effect of down
2 sampling and quantization
techniques on the grayscale image.
Write MATLAB code to enhance
the visual quality of the image
using point processing techniques,
namely
3 a) Image negative, b) Logarithmic
transformation, and c) Power law
transformation and gray level
slicing
technique.
Write MATLAB code to display
the histogram of the image and
enhance the visual quality of the
4
image with the help of histogram
equalization
technique.
Write MATLAB code to
performthe bit-plane slicing
5
method on
grayscale image.
Write MATLAB code to
demonstrate that the convolution
6 in spatial domain is
equivalent to multiplication inthe
frequency domain.
Write MATLAB code to restore
grayscale image from noisy
7
image with the help of image
restoration techniques.
Write MATLAB code to
performMin, Median & Max
8
Filtering
on grayscale image.
Write MATLAB code to blur the
image using Ideal low pass,
9 Butterworth low pass and Gaussian
Low pass filter.
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Write MATLAB code to blur the
image using Ideal High pass,
10 Butterworth High pass and
Gaussian High pass filter.
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 1
AIM: To study and implement basic commands of MATLAB required for image
processing technique, and various image file formats.
Software/Hardware: Matlab
Syntax
clc
Description
clc clears all input and output from the Command Window display, giving you a "clean screen". After
using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow
to recall statements from the command history.
2. Clear all
Remove items from workspace, freeing up system memory
Syntax
clear
clear name
clear name1 name2 name3 ... clear global name
clear -regexp expr1 expr2 ...
clear global -regexp expr1 expr2 ... clear keyword clear('name1','name2','name3',...)
Description
clear removes all variables from the workspace, releasing them from system memory.
Clear name removes just the M-file or MEX-file function or variable name from your base workspace. If
called from a function, clear name removes name from both the function workspace and in your base
workspace. You can use wildcards (*) to remove items selectively. For example, clear my* removes any
variables whose names begin with the string my. Clearing removes debugging breakpoints in M-files
and reinitializes persistent variables. If name is global, clear removes it from the current workspace, but
it remains accessible to any functions declaring it global. If name has been locked by mlock, it remains
in memory.
Use a partial path to distinguish between different overloaded versions of a function. For example, clear
polynom/display clears only the display method for polynom objects, leaving any other implementations
in memory.
clear name1 name2 name3 ... removes name1, name2, and name3 from the workspace.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
clear global name removes the global variable name. If name is global, clear name removes name from
the current workspace, but leaves it accessible to any functions declaring it as global. Use clear global
name to remove a global variable completely.
clear -regexp expr1 expr2 ... clears all variables that match any of the regular expressions listed. This
option only clears variables.
clear global -regexp expr1 expr2 ... clears all global variables that match any of the regular expressions
listed.
clear keyword clears the items indicated by keyword. See the following section, Inputs, for a list of
keywords and their descriptions.
clear('name1','name2','name3',...) is the function form of the syntax. Use this form for variable names
and function names stored in strings.
If you name a variable all, classes, functions, java, import, or variables, calling clear followed by that
name deletes the variable with that name. clear does not interpret the name as a keyword in this context.
For example, if the workspace contains variables a, all, b, and ball, clear all deletes the variable all only.
You can clear the handle of a figure or other object, but that does not remove the object itself. Use delete
to remove objects and files. Deleting an object does not delete the variable, if any, used for storing its
handle.
3. Close all
Remove specified figure
Description
close deletes the current figure or the specified figure(s). It optionally returns the status of the close
operation.
close deletes the current figure (equivalent to close(gcf)).
close(h) deletes the figure identified by h. If h is a vector or matrix, close deletes all figures identified by
h.
close name deletes the figure with the specified name. close all deletes all figures whose handles are not
hidden.
close all hidden deletes all figures including those with hidden handles.
close all force deletes all figures, including GUIs for which CloseRequestFcn has been altered to not
close the window.
status = close(...) returns 1 if the specified windows have been deleted and 0 otherwise.
4. Imread
Read image from graphics file
Syntax
A = imread(filename, fmt) [X, map] = imread(...)
[...] = imread(filename) [...] = imread(URL,...)
[...] = imread(...,Param1,Val1,Param2,Val2...)
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Description
A = imread(filename, fmt) reads a grayscale or color image from the file specified by the string
filename. If the file is not in the current folder, or in a folder on the MATLAB path, specify the full
pathname.
The text string fmt specifies the format of the file by its standard file extension. For example, specify
'gif' for Graphics Interchange Format files. To see a list of supported formats, with their file extensions,
use the imformats function. If imread cannot find a file named filename,it looks for a file named
filename.fmt.
The return value A is an array containing the image data. If the file contains a grayscale image, A is an
M-by-N array. If the file contains a true color image, A is an M-by-N-by-3 array. For TIFF files
containing color images that use the CMYK color space, A is an M-by- N-by-4 array.
The class of A depends on the bits-per-sample of the image data, rounded to the next byte boundary. For
example, imread returns 24-bit color data as an array of uint8 data because the sample size for each color
component is 8 bits.
[X, map] = imread(...) reads the indexed image in filename into X and its associated colormap into map.
Colormap values in the image file are automatically rescaled into the range [0,1]. [...] =
imread(filename) attempts to infer the format of the file from its content.
[...] = imread(URL,...) reads the image from an Internet URL. The URL must include the protocol
type (e.g., http://).
[...] = imread(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of
the operations for specific formats.
5. Title
Add title to current axes
Description
Each axes graphics object can have one title. The title is located at the top and in the center of the axes.
title('string') outputs the string at the top and in the center of the current axes.
title(fname) evaluates the function that returns a string and displays the string at the top and in the center
of the current axes.
title(...,'PropertyName',PropertyValue,...) specifies property name and property value pairs for the text
graphics object that title creates. Do not use the 'String' text property to set the title string; the content of
the title should be given by the first argument. title(axes_handle,...) adds the title to the specified axes.
h = title(...) returns the handle to the text object used as the title.
6. Subplot
Create axes in tiled positions
Syntax
h = subplot(m,n,p) or subplot(mnp) subplot(m,n,p,'replace') subplot(m,n,P)
subplot(h)
subplot('Position',[left bottom width height]) subplot(..., prop1, value1, prop2, value2, ...) h = subplot(...)
subplot(m,n,p,'v6')
Description
subplot divides the current figure into rectangular panes that are numbered row wise. Each pane contains
an axes object which you can manipulate using Axes Properties. Subsequent plots are output to the
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
current pane.
h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an m-by-n matrix of small axes,
selects the pth axes object for the current plot, and returns the axes handle. The axes are counted along
the top row of the figure window, then the second row, etc. For example, subplot (2,1,1), plot(income)
subplot (2,1,2), plot(outgo)
plots income on the top half of the window and outgo on the bottom half. If the Current Axes is nested
in a uipanel, the panel is used as the parent for the subplot instead of the current figure. The new axes
object becomes the current axes.
subplot(m,n,p,'replace') If the specified axes object already exists, delete it and create a new axes.
subplot(m,n,P), where P is a vector, specifies an axes position that covers all the subplot positions listed
in P, including those spanned by P. For example, subplot(2,3,[2 5]) creates one axes spanning positions
2 and 5 only (because there are no intervening locations in the grid), while subplot(2,3,[2 6]) creates one
axes spanning positions 2, 3, 5, and 6.
subplot(h) makes the axes object with handle h current for subsequent plotting commands.
subplot('Position',[left bottom width height]) creates an axes at the position specified by a four-
element vector. left, bottom, width, and height are in normalized coordinates in the range from 0.0
to 1.0.
subplot(..., prop1, value1, prop2, value2, ...) sets the specified property-value pairs on the subplot axes
object. Available property/value pairs are described more fully in Axes Properties. To add the subplot to
a specific figure or uipanel, pass the handle as the value for the Parent property. You cannot specify both
a Parent and a Position; that is, subplot ('Position', [left bottom width height], 'Parent',h) is not a valid
syntax.
h = subplot(...) returns the handle to the new axes object.
7. Figure
Create figure graphics object
Syntax
figure figure('PropertyName',propertyvalue,...) figure(h)
h = figure(...)
Description
figure creates figure graphics objects. Figure objects are the individual windows on the screen in which
the MATLAB software displays graphical output.
figure creates a new figure object using default property values. This automatically becomes the current
figure and raises it above all other figures on the screen until a new figure is either created or called.
figure ('PropertyName', propertyvalue,...) creates a new figure object using the values of the properties
specified. MATLAB uses default values for any properties that you do not explicitly define as
arguments.
figure(h) does one of two things, depending on whether or not a figure with handle h exists. If h is the
handle to an existing figure, figure(h) makes the figure identified by h the current figure, makes it
visible, and raises it above all other figures on the screen. The current figure is the target for graphics
output. If h is not the handle to an existing figure, but is an integer, figure(h) creates a figure and assigns
it the handle h. figure(h) where h is not the handle to a figure, and is not an integer, is an error. h =
figure(...) returns the handle to the figure object.
8. Imshow
Display image
Syntax
imshow(I) imshow(I,[low high]) imshow(RGB) imshow(BW) imshow(X,map) imshow(filename) himage
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
= imshow(...)
imshow(..., param1, val1, param2, val2,...)
Description
Parameter Value
'Border' Text string that controls whether imshow includes a border around
the image displayed in the figure window. Valid strings are 'tight' and
'loose'.
Note: There can still be a border if the image is very small, or if
there are other objects besides the image and its axes in the figure.
By default, the border is set to the
value returned by
Parameter Value
iptgetpref('ImshowBorder').
'Colormap' 2–D, real, m-by-3 matrix specifying a colormap. imshow uses this to
set the figure's colormap property. Use this parameter to view
grayscale images in false color. If you specify an empty colormap ([]),
imshow ignores this parameter.
'DisplayRange' Two-element vector [LOW HIGH] that controls the display range of
a grayscale image. See the imshow(I,[low high]) syntax for more
details about how to set this parameter.
'InitialMagnification' A numeric scalar value, or the text string 'fit', that specifies the initial
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
magnification used to display the image. When set to 100, imshow
displaysthe image at 100% magnification (one screen pixel for each
image pixel). When set to 'fit', imshow scales the entire image to fit in
the window.
On initial display, imshow always displays the entire image. If the
magnification value is large enough that the image would be too big
to display on the screen, imshow warns and displays the image at the
largest magnification that fits on the screen.
By default, the initial magnification parameter is set to the value
returned by iptgetpref ('Imshow Initial Magnification').
If the image is displayed in a figure with its 'WindowStyle' property
set to 'docked', imshow warns and displays the image at the largest
magnification that fits in the figure.
Note: If you specify the axes position (using subplot or axes),
imshow ignores any initial magnification you might have specified
and defaults to the 'fit'behavior.
When used with the 'Reduce' parameter, only 'fit' is allowed as an
initial magnification.
'Parent' Handle of an axes that specifies the parent of the image object that
will be created by imshow.
'Reduce' Logical value that specifies whether imshow subsamples the image in
filename. The 'Reduce' parameter is only valid for TIFF images and
you must specify a file name. Use this parameter to display
overviews of very large images.
'XData' Two-element vector that establishes a nondefault spatial coordinate
system by specifying the image XData. The value can have more than
two elements, but only the first and last elements are actually used.
'YData' Two-element vector that establishes a nondefault spatial coordinate
system by specifying the image YData. The value can have more than
two elements, but only the first and last elements are actually used.
9. Size
Array dimensions
Syntax
d = size(X) [m,n] = size(X) m = size(X,dim)
[d1,d2,d3,...,dn] = size(X),
Description
d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements. If X is
a scalar, which MATLAB software regards as a 1-by-1 array, size(X) returns the vector [1 1].
[m,n] = size(X) returns the size of matrix X in separate variables m and n.
m = size(X,dim) returns the size of the dimension of X specified by scalar dim. [d1,d2,d3,...,dn] =
size(X), for n> 1, returns the sizes of the dimensions of the array X in the variables d1,d2,d3,...,dn,
provided the number of output arguments n equals ndims(X). If n does not equal ndims(X), the
following exceptions hold:
n < ndims(X) di equals the size of the ith dimension of X for , but dn equals the product
of the sizes of the remaining dimensions of X, that is, dimensions n through ndims(X).
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
n > ndims(X) size returns ones in the "extra" variables, that is, those corresponding to ndims(X)+1
through n.
10. Double
Convert to double precision
Syntax
double(x)
Description
double(x) returns the double-precision value for X. If X is already a double-precision array, double has
no effect.
11. Imagesc
Scale data and display image object
Syntax
The imagesc function scales image data to the full range of the current colormap and displays the image.
imagesc(C) displays C as an image. Each element of C corresponds to a rectangular area in the image.
The values of the elements of C are indices into the current colormap that determine the color of each
patch.
imagesc(x,y,C) displays C as an image and specifies the bounds of the x- and y-axis with vectors x and
y. If x(1) > x(2) or y(1) > y(2), the image is flipped left-right or up-down, respectively.
imagesc(...,clims) normalizes the values in C to the range specified by clims and displays C as an image.
clims is a two-element vector that limits the range of data values in C. These values map to the full
range of values in the current colormap. imagesc('PropertyName',PropertyValue,...) is the low-level
syntax of the imagesc function. It specifies only property name/property value pairs as input arguments.
h = imagesc(...) returns the handle for an image graphics object.
12. Addpath
Add folders to search path
Syntax
addpath('folderName1','folderName2','folderName3' ...)
addpath('folderName1','folderName2','folderName3' ...position) addpath folderName1 folderName2
folderName3 ... –position
Description
addpath ('folderName1','folderName2','folderName3' ...) adds the specified folders to the top of the
search path. Use the full path name for each folder. Use genpath with addpath to add all subfolders of
folder Name. Use addpath statements in a startup.m file to modify the search path programmatically at
startup.
addpath('folderName1','folderName2','folderName3' ...position) adds the specified folders to either the
top or bottom of the search path, depending on the value of position.
13. Clf
Clear current figure window
Description
clf deletes from the current figure all graphics objects whose handles are not hidden (i.e., their
HandleVisibility property is set to on).
clf('reset') deletes from the current figure all graphics objects regardless of the setting of their
HandleVisibility property and resets all figure properties except Position, Units, PaperPosition, and
PaperUnits to their default values.
clf(fig) or clf(fig,'reset') clears the single figure with handle fig.
figure_handle = clf(...) returns the handle of the figure. This is useful when the figure IntegerHandle
property is off because the noninteger handle becomes invalid when the reset option is used (i.e.,
IntegerHandle is reset to on, which is the default).
14. Imwrite
Syntax
Description
imwrite(A,filename,fmt) writes the image A to the file specified by filename in the format specified by
fmt.
A can be an M-by-N (grayscale image) or M-by-N-by-3 (true color image) array, but it cannot be an
empty array. For TIFF files, A can be an M-by-N-by-4 array containing color data that uses the CMYK
color space. For GIF files, A can be an M-by-N-by-1-by-P array containing grayscale or indexed images
— RGB images are not supported. For information about the class of the input array and the output
image,
filename is a string that specifies the name of the output file.
imwrite(X, map, filename, fmt) writes the indexed image in X and its associated colormapmap to
filename in the format specified by fmt. If X is of class uint8 or uint16, imwrite writes the actual values
in the array to the file. If X is of class double, imwrite offsets the values in the array before writing,
using uint8(X–1). map must be a valid MATLAB colormap. Note that most image file formats do not
support colormaps with more than 256 entries.When writing multiframe GIF images, X should be an 4-
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
dimensional M-by-N-by-1-by-P array, where P is the number of frames to write.
imwrite(...,filename) writes the image to filename, inferring the format to use from the filename's
extension.
imwrite(...,Param1,Val1,Param2,Val2...) specifies parameters that control various characteristics of the
output file for HDF, JPEG, PBM, PGM, PNG, PPM, and TIFF files. For example, if you are writing a
JPEG file, you can specify the quality of the output image.
15. Imfinfo
Information about graphics file
Syntax
info = imfinfo(filename,fmt) info = imfinfo(filename) info = imfinfo(URL,...)
Description
info = imfinfo(filename,fmt) returns a structure whose fields contain information about an image in a
graphics file. filename is a string that specifies the name of the graphics file, and fmt is a string that
specifies the format of the file. The file must be in the current folder or in a folder on the MATLAB
path. If imfinfo cannot find a file named filename, it looks for a file named filename.fmt. The possible
values for fmt are contained in the MATLAB file format registry.
If filename is a TIFF, HDF, ICO, GIF, or CUR file containing more than one image, info is a structure
array with one element for each image in the file. For example, info(3) would contain information about
the third image in the file.
info = imfinfo(filename) attempts to infer the format of the file from its contents.
info = imfinfo(URL,...) reads the image from the specified Internet URL. The URL must include the
protocol type (e.g., http://)
16. Resize
Enlarge or shrink image sizes
Library
Geometric Transformations
Description
The Resize block enlarges or shrinks an image by resizing the image along one dimension (row or
column). Then, it resizes the image along the other dimension (column or row).
Complex
Port Input/Output Supported Data Types Values
Supported
Image M-by-N matrix of • Double-precision floating No
/ Input intensity values or an M- point
by-N-by-P color video • Single-precision floating
signal where P is the point
number of color planes • Fixed point
• 8-, 16-, 32-bit signed
integer
• 8-, 16-, 32-bit unsigned
integer
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
ROI Four-element vector that • Double-precision No
defines the ROI floating point (only
supported if the input to the
Input port is floating point)
• Single-precision floating
point (only supported if the
input to the Input port is
floating point)
• 8-, 16-, 32-bit signed
integer
• 8-, 16-, 32-bit unsigned
integer
Output Resized image Same as Input port No
Flag Boolean value that Boolean No
indicates whether the ROI
is within the image
bounds
17. Who
List names of top-level data logging objects in Simulink data log
Syntax
Description
log.who or who(log) lists the names of the top-level signal logging objects contained by log, where log
is the handle of a Simulink.ModelDataLogs object name.
tsarray.who or who(tsarray) lists the names of Simulink.TimeSeries objects contained by the
Simulink.TsArray object named tsarray.
log.who('systems') or who(log, 'systems') lists the names of all signal logging objects contained by log
except for Simulink.Timeseries objects stored in Simulink.TsArray objects contained by log.
log.who('all') or who(log, 'all') lists the names of all the Simulink.Time series objects contained by the
Simulink.ModelDataLogs, Simulink. TsArray, or Simulink.SubsysDataLogs object named log.
18. Whos
List names and types of top-level data logging objects in Simulink data log
Description
log.whos or whos(log) lists the names and types of the top-level signal logging objects contained
by log, where log is the handle of a Simulink.ModelDataLogs object name.
tsarray.whos or whos(tsarray) lists the names and types of Simulink.TimeSeries objects contained by the
Simulink.TsArray object named tsarray.
log.whos('systems') or whos(log, 'systems') lists the names and types of all signal logging objects
contained by log except for Simulink.Timeseries objects stored in Simulink.TsArray objects contained
by log.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
log.whos('all') or whos(log, 'all') lists the names and types of all the Simulink.Timeseries objects
contained by the Simulink.ModelDataLogs, Simulink.TsArray, or Simulink.SubsysDataLogs object
named log.
Conclusion:
This lab helped reinforce the foundational concepts of image processing and MATLAB's powerful
capabilities for handling image data. The practical implementation of these commands laid the
groundwork for more advanced image processing techniques and applications in future studies.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 2
AIM: To study the effect of down sampling and quantization techniques on the
grayscale image Software/ Hardware: MATLAB
Objective: The objective of the experiment is to,
⚫ Sampling and quantization techniques on the grayscale image.
⚫ Display effect of down sampling and quantization with help of the MATLAB code.
Code:
clc;
clear all;
close all;
i=imread('cameraman.tif');
figure();
subplot(1,4,1);
imshow(i);
title('original image');
[r,c]=size(i);
a=i(1:2:r,1:2:c);
subplot(1,4,2);
imshow(a);
title('Sampling');
d=i(1:3:r,1:3:c);
subplot(1,4,3);
imshow(d);
title('Sampling');
b=i(1:4:r,1:4:c);
subplot(1,4,4);
imshow(b);
title('Sampling');
i=imread('cameraman.tif');
b=imresize(i,0.5,'nearest');
figure();
subplot(1,3,1);
imshow(b);
title('nearest');
b1=imresize(i,0.5,'bilinear');
subplot(1,3,2);
imshow(b1);
title('bilinear');
b2=imresize(i,0.5,'bicubic');
subplot(1,3,3);
imshow(b2);
title('bicubic');
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Simulation Results:
Output: We got the sampling and quantization(nearest, bilinear and bicubic) of the original image of
cameraman.
Conclusion: We study the effect of down sampling and quantization techniques on the grayscale image.
of cameraman.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 3
AIM: Write MATLAB code to enhance the visual quality of the image using point
processing techniques, namely a) Image negative, b) Logarithmic transformation, c)
Power law transformation and d) Gray level slicing technique.
Software/ Hardware: MATLAB
Theory:
a) Image Negative: This is an image processing technique where the colors or intensities in an
image are inverted. In a grayscale image, this means that lighter areas become darker and vice versa.
In a colored image, each color channel is inverted independently.
b) Logarithmic Transformation: A type of image enhancement technique where the pixel values
in an image are transformed using a logarithmic function. This transformation is often used to expand
the dynamic range of darker areas in the image while compressing the range of brighter areas.
c) Power Law Transformation: Also known as gamma correction, this transformation involves
raising the pixel values in an image to a power law function. It is used to adjust the contrast and
brightness of an image, especially in cases where the image's histogram is concentrated towards either
the low or high intensity values.
d) Gray Level Slicing Technique: This technique is used to highlight specific ranges of pixel
intensity values in an image. It involves thresholding the pixel values into different intensity bands or
levels. Pixels within a specified range are retained, while others are set to a particular value, typically
resulting in enhanced features or segmentation of objects based on their intensity levels.
Code:
clc;
clear all ;
close all;
a = imread('/MATLAB Drive/WhatsAppImage2023-10-21 at 11.46.10_48d9fed9.jpg');
i=rgb2gray(a);
i=double(i); s=255-i;
figure(); subplot(4,2,1);
imshow(uint8(i)),title('Gray scale');
subplot(4,2,2); imshow(s,[]);
title('Negative image'); c=5;
s1=c*log(1+i);
subplot(4,2,3);
imshow(uint8(s1));
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
title('log image');
s2=(exp(i).^(1\c))-1; subplot(4,2,4);
imshow(uint8(s2));
title('antilog image') gamma=0.4;
s3=c*(i.^gamma); subplot(4,2,5);
imshow(uint8(s3));
th=15;
[r,c]=size(i);
for x=1:1:r;
for y=1:1:c;
if (i(x,y)<=th)
i(x,y)=0;
else
i(x,y)=255;
end
end
end
subplot(4,2,6);
imshow(uint8(i));
title('threshold image');
Simulation Results:
Input: Image
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Conclusion:
In this practical, we enhanced the quality of input image using point processing techniques i.e.
a) Image negative
b) Logarithmic transformation
c) Power law transformation
d) Gray level slicing technique
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 4
AIM: Write MATLAB code to display the histogram of the image and enhance the
visual quality of the image with the help of histogram equalization technique.
Software/ Hardware: MATLAB
Theory:
• The histogram of an image represents the frequency distribution of pixel intensities. It plots the
number of pixels for each intensity value.
• To display the histogram, you first need to compute it. You can do this by iterating through all the
pixels in the image and counting the occurrences of each intensity value.
• Once you have computed the histogram, you can plot it using a histogram plotting tool or library.
The x- axis represents the intensity values, while the y-axis represents the frequency of occurrence.
• By visualizing the histogram, you can gain insights into the distribution of pixel intensities in the
image. This can help you understand the overall brightness and contrast characteristics of the image.
Histogram Equalization:
• Histogram equalization is a technique used to improve the contrast of an image by redistributing the
intensity values.
• The goal of histogram equalization is to transform the intensity values of the image such that the
histogram of the output image is approximately flat.
• This technique involves computing a cumulative distribution function (CDF) of the histogram and
then mapping the original intensity values to new values based on this CDF.
• The mapping function is typically computed as follows: s=T(r)=L−1N×M∑j=0rnjs = T(r) = \
frac{{L- 1}}{{N \times M}} \sum_{j=0}^{r} n_js=T(r)=N×ML−1∑j=0rnj where T(r)T(r)T(r) is the
mapping function, LLL is the number of intensity levels (typically 256 for an 8-bit image), N×MN \
times MN×M is the total number of pixels in the image, rrr is the original intensity value, and njn_jnj is
the cumulative histogram up to intensity value rrr.
• After applying histogram equalization, the resulting image will have improved contrast and
enhanced visual quality.
• Histogram equalization redistributes pixel intensities to utilize the entire dynamic range of intensity
values available in the image.
• This can lead to better utilization of available brightness levels, resulting in improved contrast and
clarity.
• However, it's important to note that histogram equalization may sometimes lead to unnatural-looking
images, especially if the original histogram is heavily skewed.
• To address this, adaptive histogram equalization techniques can be used, which divide the image into
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
smaller regions and perform histogram equalization locally. This helps to preserve local contrast while
enhancing the overall image quality.
Code:
clc;
clear all;
close all;
i = imread('cameraman.tif');
J = imadjust(i);
figure();
imshow(i);
title('ORIGINAL IMAGE');
figure()
subplot(3,3,1);
imshow(J);
title('ADJUSTED Image');
subplot(3,3,2);
imhist(J);
title('Histogram of Adjusted Image')
J1=imadjust(i,[0.4 0.5],[0.4 0.5]);
subplot(3,3,3);
imshow(J1);
title('CONTRAST ADJUST');
S= imadjust(i,stretchlim(i),[0.10 0.99]);
subplot(3,3,4);
imhist(J1);
title('Histogram of contrast adjust');
subplot(3,3,5);
imshow(S);
title('STRETCH');
subplot(3,3,6);
imhist(S);
title("Histogram of Stretch")
AH=adapthisteq(i);
subplot(3,3,7);
imshow(i);
title('ORIGINAL IMAGE');
subplot(3,3,8);
imshow(AH);
title('ADAPTIVE HIST');
subplot(3,3,9);
imhist(AH)
title("Histogram of Adaptive Hist")
% background = imopen(i,strel('disk',2))
% subplot(3,3,9);
% imshow(background);
% removal = i- background;
% subplot(3,3,6);
% imshow(removal);
% title('background removal');
% i3=imadjust(removal);
% figure(3);subplot(3,3,1);imshow(i);title('ORIGINAL');
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
% subplot(3,3,2);imshow(removal),title('BACKGROUND REMOVE');
% subplot(3,3,3);imshow(i3);title('removal adjust');
% level = graythresh(i);
% bw = im2bw(i,level);
% bw = bwareaopen(bw, 50);
% subplot(3,3,4), imshow(bw);title('binary imaage');
% cc = bwconncomp(bw, 4)
% cc.NumObjects
% figure(2), surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
% set(gca,'ydir','reverse');
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Conclusion: In this practical we displayed the histogram of the image and enhanced the visual quality
of the image with the help of histogram equalization technique.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 5
AIM: Write MATLAB code to perform the bit-plane slicing method on grayscale
Theory:
Bit-plane slicing is a technique used in image processing to decompose an image into its binary bit-
planes. Each bit-plane represents a specific bit (0 or 1) of the pixel values in the image. This method is
useful for various
Code:
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Simulation Results
Conclusion: In this practical we performed the bit-plane slicing method on grayscale image.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 6
AIM: Write MATLAB code to demonstrate that the convolution in spatial domain is
equivalent to multiplication in the frequency domain.
Software/ Hardware: MATLAB
Objective: The objective of the experiment is to, demonstrate that the convolution in spatial domain is
equivalentto multiplication in the frequency domain.
Theory:
The statement you provided is a fundamental concept in signal processing and image processing, known
as the Convolution Theorem. It states that convolution in the spatial domain (i.e., directly operating on
the pixel values of an image) is equivalent to multiplication in the frequency domain (i.e., operating on
the Fourier transforms of the images).
Code:
% Compute the inverse Fourier transform to get the result in the spatial domain
convResult = ifft2(convFrequency);
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
% Display the result of convolution in the spatial domain
figure;
imshow(uint8(convSpatial)); title('Convolution in Spatial Domain');
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Input: Convolution in spatial domain.
Conclusion: In this experiment we demonstrated that the convolution in spatial domain is equivalent to
multiplication in the frequency domain.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 7
AIM: Write MATLAB code to restore grayscale image from noisy image with the
help of image restoration techniques.
Objective:
The objective of the experiment is to,
• Get basic information of sampling and quantization techniques on grayscaleimage.
• Display all techniques on MATLAB using MATLAB code.
1. Reading an Image:
filteredImage = medfilt2(image);
6. Saving an Image:
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
combinedFiltered = wiener2(medianFiltered, [5 5]);
Theory:
Image restoration techniques are essential for improving the quality of images corrupted by noise. The
goal is to recover the original image by reducing or eliminating the noise while preserving important
details. Common techniques for restoring grayscale images from noisy images include median filtering
and Wiener filtering.
Median Filtering
Median filtering is a nonlinear method that reduces noise by replacing each pixel's value with the
median value of its neighboring pixels. It is particularly effective at removing salt-and-pepper noise
(impulsive noise) .
Wiener Filtering
Wiener filtering is a linear method based on statistical principles. It aims to minimize the mean square
error between the restored image and the original image. This filter adapts to the local mean and
variance of the image, making it effective for reducing Gaussian noise.
A combined approach using both median and Wiener filtering can enhance the noise reduction process.
By applying median filtering first to remove impulsive noise and then Wiener filtering to reduce
Gaussian noise, a more comprehensive noise reduction can be achieved.
Implementation in MATLAB
Using MATLAB, the process of restoring a grayscale image from a noisy image involves the following
steps:
Code:
% Read the noisy grayscale image
noisyImage = imread('\dog.jpg');
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Input:
Output:
Conclusion:
We matplot code to restore grayscale image from noisy image with the help of image restoration
techniques.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 8
AIM: Write MATLAB code to perform Min, Median & Max Filtering on grayscale
Theory:
• Min Filtering: Replaces each pixel in the image with the minimum pixel value in its
neighborhood. It is often used to reduce noise in images and preserve edges.
• Median Filtering: Replaces each pixel with the median value in its neighborhood. It effectively
removes noise while preserving edges better than mean or min filtering.
• Max Filtering: Replaces each pixel with the maximum pixel value in its neighborhood. It can be
used for tasks like finding the brightest regions in an image.
Code:
clc; clear all; close all;
end
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Input:
Output:
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Conclusion:
We have successfully perform MATLAB code to perform Min, Median & Max Filtering on grayscale.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 9
AIM: Write MATLAB code to blur the image using Ideal low pass, Butterworth
low pass and Gaussian Low pass filter.
Objective: The objective of the experiment is to, Syntax: Syntax to be covered in this experiment,
Theory:
a) Ideal Low Pass Filter: An ideal low pass filter is a theoretical filter that allows all frequencies
below a certain cutoff frequency to pass through unchanged, while completely blocking all frequencies
above that cutoff. In practice, it's impossible to create a perfect ideal filter due to issues like Gibbs
phenomenon, which causes ringing artifacts in the filtered image.
b) Butterworth Low Pass Filter: A Butterworth low pass filter is a type of filter commonly used
in signal processing and image processing. It is designed to allow frequencies below a certain cutoff
frequency to pass through with minimal attenuation, while attenuating higher frequencies progressively.
It provides a smoother roll-off compared to the ideal filter and is defined by its order and cutoff
frequency.
c) Gaussian Low Pass Filter: A Gaussian low pass filter is a filter where the frequency response is
defined by a Gaussian function. It attenuates higher frequencies more than lower frequencies, gradually
smoothing the image. It's often used in image processing for noise reduction and blurring while
preserving the overall structure of the image. The amount of smoothing is controlled by the standard
deviation parameter of the Gaussian function.
Code:
output_image1 = real(ifft2(double(Gil)));
output_image2 = real(ifft2(double(Gbl)));
output_image3 = real(ifft2(double(Ggl)));
figure()
subplot(2, 1, 1), imshow(i),
subplot(2, 1, 2), imshow(output_image2, [ ]);
figure()
subplot(2, 1, 1), imshow(i),
subplot(2, 1, 2), imshow(output_image3, [ ]);
figure()
subplot(2,2,1);imshow(i);title('Original image'); subplot(2,2,2);imshow(output_image1, []);title('Idle Low
Pass'); subplot(2,2,3);imshow(output_image2,[]);title('Butterworth Low Pass');
subplot(2,2,4);imshow(output_image3,[]);title('Gaussian Low Pass');
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Input:
Output:
Conclusion:
We have successfully concluded MATLAB code to blur the image using Ideal low pass, Butterworth
low pass and Gaussian Low pass filter.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
EXPERIMENT NO: 10
AIM: Write MATLAB code to blur the image using Ideal High pass, Butterworth
High pass and Gaussian High pass filter.
Theory:
• The ideal high-pass filter rejects or attenuates low-frequency components (i.e., smooth areas)
of an image while preserving or passing high-frequency components (i.e., edges and details).
• It is characterized by a sharp transition from attenuation to preservation at a specified
cutoff frequency. Frequencies above the cutoff are passed, and frequencies below are attenuated.
• The main drawback of the ideal high-pass filter is that it has infinite support in the frequency
domain, resulting in ringing artifacts in the spatial domain.
• The Butterworth high-pass filter is a type of high-pass filter with a smoother transition
between the passband (where frequencies are preserved) and the stopband (where frequencies are
attenuated) compared to the ideal filter.
• It is characterized by a parameter called the order (n), which determines the rate of rolloff
from the passband to the stopband. Higher order filters have steeper rolloffs.
• Butterworth filters are preferred over ideal filters when a smoother transition is desired, as
they produce fewer ringing artifacts.
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Code:
clc; clear all; close all;
i = imread('dog.jpg');
i = rgb2gray(i);
[M, N] = size(i);
FT_img = fft2(double(i));
u = 0:(M-1);
idx = find(u>M/2);
u(idx) = u(idx)-M;
v = 0:(N-1);
idy = find(v>N/2);
v(idy) = v(idy)-N;
[V, U] = meshgrid(v, u);
figure()
subplot(2, 1, 1), imshow(i), title('Original image');
subplot(2, 1, 2), imshow(output_image2, []), title('Butterworth High Pass');
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
figure()
subplot(2, 1, 1), imshow(i), title('Original image');
subplot(2, 1, 2), imshow(output_image3, []), title('Gaussian High Pass');
figure()
subplot(2, 2, 1), imshow(i), title('Original image');
subplot(2, 2, 2), imshow(output_image1, []), title('Ideal High Pass'); subplot(2, 2, 3),
imshow(output_image2, []), title('Butterworth High Pass'); subplot(2, 2, 4), imshow(output_image3, []),
title('Gaussian High Pass');
Simulation Results
210305124014
PARUL UNIVERSITY
FACULTY OF ENGINEERING & TECHNOLOGY
Image Processing (203105471) B. Tech. 4th Year
Input:
Output:
Conclusion:
We have successfully conducted MATLAB code to blur the image using Ideal High pass, Butterworth
High pass and Gaussian High pass filter.
210305124014