Practical Image and Video Processing
Using MATLAB
Lecture 8 Histogram processing
(courtesy of Oge Marques)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
What will we learn?
What is the histogram of an image?
How can the histogram of an image be computed?
How much information does the histogram provide about
the image?
What is histogram equalization and what happens to an
image whose histogram is equalized?
How can the histogram be modified through direct
histogram specification and what happens to an image
when we do it?
What other histogram modification techniques can be
applied to digital images and what is the result of applying
such techniques?
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
What is a histogram?
The histogram of a monochrome image is a
graphical representation of the frequency of
occurrence of each gray level in the image.
The data structure that stores the frequency values
is a 1D array of numerical values, h, whose
individual elements store the number (or
percentage) of image pixels that correspond to each
possible gray level.
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
What is a histogram?
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram example
Example 9.1: histogram for a hypothetical image
containing 128128 pixels and 8 gray levels.
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Examples of images and their histograms
(Example 9.2)
In MATLAB: imhist
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Examples of images and their histograms
(Example 9.2)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Examples of images and their histograms
(Example 9.2)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Examples of images and their histograms
(Example 9.2)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Interpreting image histograms
Histograms have become a popular tool for
conveying image statistics and helping determine
certain problems in an image.
A histogram carries significant qualitative and
quantitative information about the corresponding
image (e.g., minimum, average, and maximum gray
level values, dominance of bright or dark pixels,
etc.).
A histogram is not enough to draw qualitative
conclusions about the overall quality of the image,
presence or absence of noise, etc.
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Interpreting image histograms
Although a histogram provides the frequency
distribution of gray levels in an image, it tells us
nothing about the spatial distribution of the pixels
whose gray levels are represented in the histogram.
Histograms can be used whenever a statistical
representation of the gray level distribution in an
image is desired.
Histograms can also be used to enhance or modify
the characteristics of an image, particularly its
contrast.
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram equalization
Example 9.3:
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram equalization
In MATLAB: histeq
Example 9.4:
I = imread('sydney_low_contrast.png');
I = im2double(I);
J = histeq(I);
figure, subplot(2,2,1), imshow(I), ...
subplot(2,2,2), imshow(J), ...
subplot(2,2,3), imhist(I), ylim('auto'),...
subplot(2,2,4), imhist(J), ylim('auto')
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram equalization
Example 9.4:
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Global vs. local histogram equalization
In MATLAB: histeq and adapthisteq
Example 9.5:
I = imread('coins.png');
figure, subplot(1,2,1), imshow(I), ...
subplot(1,2,2), imhist(I), ylim('auto')
J = histeq(I);
figure, subplot(1,2,1), imshow(J), ...
subplot(1,2,2), imhist(J), ylim('auto')
K = adapthisteq(I);
figure, subplot(1,2,1), imshow(K), ...
subplot(1,2,2), imhist(K), ylim('auto')
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Global vs. local histogram equalization
Example 9.5:
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Direct histogram specification
Example 9.6:
Original
Desired
Result
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Direct histogram specification
In MATLAB: histeq
Example 9.7:
I = imread('sydney_low_contrast.png');
Id = im2double(I);
figure, imhist(Id), ylim('auto'), ...
title ('Original histogram');
des_hist = uint8(zeros(1,256));
des_hist(1:128) = linspace(256,0,128);
des_hist(129:end) = linspace(0,256,128);
x_axis = 0:255;
figure, bar(x_axis, des_hist), axis tight,
...
title('Desired histogram');
hgram = im2double(des_hist);
Jd = histeq(Id,hgram);
figure, imhist(Jd), ylim('auto'), ...
title ('Resulting histogram');
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Direct histogram specification
Example 9.7:
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Direct histogram specification
Interactive histogram matching tool (ihmdemo)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Other histogram modification techniques
Histogram sliding (Example 9.8):
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram sliding
In MATLAB: imadd and imsubtract
Example 9.8:
I = imread('schonbrunn_gray_low_contrast.png');
figure, imhist(I), ylim('auto'), title ('Original histogram');
I2 = imadd(I, 50);
figure, imhist(I2), ylim('auto'), ...
title ('Sliding to the right by 50');
I3 = imsubtract(I,50);
figure, imhist(I3), ylim('auto'), ...
title ('Sliding to the left by 50');
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Other histogram modification techniques
Histogram stretching (Example 9.9):
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Other histogram modification techniques
Histogram shrinking (Example 9.10):
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Histogram stretching and shrinking
In MATLAB: imadjust
%% Histogram stretching
I = imread('schonbrunn_gray_low_contrast.png');
figure, imhist(I), ylim('auto'), title ('Original histogram');
I2 = imadjust(I);
figure, imhist(I2), ylim('auto'), title ('After histogram stretching');
figure, subplot(1,2,1), imshow(I), subplot(1,2,2), imshow(I2)
%% Histogram shrinking
I = imread('schonbrunn_gray.png');
figure, imhist(I), ylim('auto'), title ('Original histogram');
Id = im2double(I);
Jd = imadjust(Id, [], [49/255 140/255]);
J = uint8(255.*Jd);
figure, imhist(J), ylim('auto'), title ('After histogram shrinking');
figure, subplot(1,2,1), imshow(I), subplot(1,2,2), imshow(J)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
Hands-on
Tutorial 9.1: Image histograms (page 188)
Tutorial 9.2: Histogram equalization and
specification (page 191)
Tutorial 9.3: Other histogram modification
techniques (page 195)
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.
References
Practical Image and Video Processing
Using MATLAB, Oge Marques, Chapter 9
By Oge Marques
Copyright 2011 by John Wiley & Sons, Inc. All rights reserved.