Documente Academic
Documente Profesional
Documente Cultură
Chapter 3
Image Enhancement in the Spatial Domain
Part 2
1. Theoretical
Histogram Processing
Histogram of a digital image with gray levels in the range [0,L-1] is a discrete
function:
h(rk) = nk
Where rk is the kth gray level and nk is the number of pixels in the image having level rk.
Example1
It is a common practice to normalize the histogram by dividing each of its values by the
total number of pixels in the image, denoted by n.
p(rk) = nk/n
1
p(rk) = nk/MN , k=0, 1, …, L-1
p(rk) gives an estimate of the probability of occurrence of a gray level rk.
The sum of all components of a normalized histogram is equal to 1.
Histogram Equalization
It is an enhancement technique which is related to the probability density function of the gray
levels of the input image, would give an output image of uniformly distributed gray levels.
The goal of histogram equalization is to spread out the contrast of a given image evenly
throughout the entire available dynamic range.
PDF can be approximated using the probability based on the histogram as follows:
From this pdf, we can then obtain the cumulative density function (CDF) as follows:
The output pixels from the histogram equalization operation is then equals to the cdf
of the image or mathematically:
To get the value of the pixel, need to be multiplied by [L – 1] and then round it to the
nearest integer.
Example2:
2
a) Find image Histogram.
Solution:
Solution:
The pdf for this image can be computed simply by taking the histogram above and
divided each value by the number of total pixels (16 in this example).
Solution:
The cdf of this image matrix is computed as an accumulation of the above histogram.
To get the value of the pixel s, need to be multiplied by 7 and then round it to the nearest
integer. The output is:
3
Histogram Matching (Histogram Specification)
Histogram matching is an extension to the histogram equalization technique. In histogram
equalization technique, what we are trying to achieve is that the output histogram should follow
the uniform pdf. However, for histogram matching, we want the output histogram to follow
according to the histogram we specify. To achieve this, we first histogram equalize the input
image, then the pdf of this resulting equalized image will be matched to the pdf of the desired
histogram.
Example3:
Consider the following 4x4 matrix of a 3-bit image and the desired histogram:
Solution:
From this desired histogram, we come up with the desired cdf i.e. by accumulating the
probability of the desired histogram. This is shown in the table below:
r 0 1 2 3 4 5 6 7
1.PDF = p(rk) 0.1875 0.25 0.3125 0 0.0625 0.0625 0 0.125
2.CDF = p(sk) 0.1875 0.4375 0.75 0.75 0.8125 0.875 0.875 1
3.PDF = p(rrk) 0.125 0.1875 0.1875 0.1875 0.125 0.0625 0.0625 0.0625
4.CDF = p(zk) 0.125 0.3125 0.5 0.6875 0.8125 0.875 0.9375 1
s 0 2 3 3 4 5 5 7
For p(s0) = 0.1875, the nearest value for p(zk) is 0.125, which is for z0. Hence, the output
pixel corresponding to r = 0 is s = 0. Then p(s1) = 0.4375, the nearest value for p(zk) is
0.5, which is for z2. Hence, the output pixel corresponding to r = 1 is s = 2.
The process is continued until we’ve done the last pixel. The output matrix then will be
as follows:
4
2. Practical
Example1: Image Histogram
%hist_ex.m
close all;
clear all;
i=imread('ch3_1.jpg');
I=rgb2gray(i);
I=im2double(I);
m=im2bw(I,1); %Black
subplot 121,imhist(I),title('Gray Image'),ylim('auto');
subplot 122,imhist(m),title('Binary Image'),ylim('auto');
Output:
5
Output: