Professional Documents
Culture Documents
Experiment No. 5
Spatial Domain Processing – Image Histogram
Object:
The purpose of this experiment is to develop and illustrate MATLAB formulations representative of
processing techniques in spatial domain.
Introduction:
The term spatial domain refers to the image plane itself, and methods in this category are based on direct
manipulation of pixels in an image.
Procedure:
1. Image Complement: This process is used for obtaining a photographic negative, it is particularly
useful for enhancing white or gray detail embedded in a large, predominantly dark region.
2. IM = imcomplement(MyImage)
Example:
MyImage = imread(‘D:\cameraman.jpg’);
IM = imcomplement(MyImage);
imshow(MyImage) figure, imshow(IM)
(1 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Image Complement
3. Image histograms: An image histogram is a chart that shows the distribution of intensities in an
image. It plays a basic role in image processing, in areas such as enhancement, compression,
segmentation, and description.
h = imhist(MyImage) Example:
MyImage = imread(‘D:\cameraman.jpg’);
Figure, imhist(MyImage)
Image histogram
(2 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
There are other ways to plot the image histogram, depending on image processing applications.
bar graph:
bar(horz, vert)
where vert is a row vector containing the points to be plotted,
horz is a vector of the same dimension as vert that contains the increments of the horizontal scale. When
plotting a bar graph, it is customary to reduce the resolution of the horizontal axis by dividing it into bands
Example:
MyImage = imread(‘D:\cameraman.jpg’); h = imhist(MyImage) horz =
1:10:256; % reduce the horizontal resolution by 10 vert =
h(1:10:256); bar(horz, vert) axis([0 255 0 2000]) set(gca, 'xtick',
0:50:255) set(gca, 'ytick', 0:250:2000)
Bar Histogram
(3 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Example:
MyImage = imread(‘D:\cameraman.jpg’);
h= imhist(MyImage)
horz = 1:10:256; % reduce the horizontal resolution by 10
vert = h(1:10:256);
set(gca,'ytick', 0:250:2000)
(4 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Stem Histogram
plot: The set of points are plotted by linking them with straight lines.
Example:
MyImage = imread(‘D:\cameraman.jpg’);
h = imhist(MyImage) plot(h) % Use
the default values.
axis([0 255 0 2000])
set(gca,'xtick', 0:50:255)
set(gca,'ytick', 0:250:2000)
Plot Histogram
(5 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
4. Histogram Equalization: it is the technique for adjusting image intensities to enhance contrast by
spreading the levels of the input image over a wider range of the intensity scale. It is used for images that
have poor contrast, images that look like they're too dark, or if they're too bright. g = histeq(f, nlev) where f
is the input image and nlev is the number of intensity levels specified for the output image.
Example:
f = imread(‘D:\cameramandark.jpg’);
imshow(f) figure, imhist(f)
ylim('auto') g = histeq(f, 256); figure,
imshow(g) figure, imhist(g)
ylim('auto')
(6 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Histogram Equalization
(7 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Histogram Matching
(8 - 5)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Lab Work:
Execute all four Image Histograms ways to plot the image cameraman dark and see the
differences between it and the original cameraman image
Define a (sign) like PDF as the desired output histogram to enhance (cameramandak) image Hint
I = imread('D:\cameramandark.jpg');
hspec1 = linspace(0,3.14,256); %Define ramp like pdf as desired output histogram hspec
= sin(hspec1);
Im = histeq(I, hspec); %Supply desired histogram to perform matching
subplot(2,3,1), imshow(I); subplot(2,3,2), imshow(Im);
subplot(2,3,3), plot(hspec); subplot(2,3,4), imhist(I); subplot(2,3,5),
imhist(Im);
(9 - 5)