Sunteți pe pagina 1din 6

Islamic University Of Gaza Digital Image Processing

Faculty of Engineering Discussion


Computer Department Chapter 3
Eng. Ahmed M. Ayash Date: 17/03/2013

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.

Thus a normalized histogram is given by:

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.

 In histogram equalization technique, it is the probability density function (pdf) that is


being manipulated.

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:

where p(rk) is the probability for pixel of intensity .

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:

Consider the following 4x4 matrix of a 3-bit image.

2
a) Find image Histogram.

Solution:

b) Find the PDF for this image.

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).

c) Find the CDF for this image.

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:

Find the Histogram Matching of this image.

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

 1 and 2 for the given image.


 3 and 4 for the desired histogram.

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:

Example2: Histogram Equalization


%histeq_ex.m
clc
close all
clear all
f = imread('pollen.tif');
g = histeq(f);
subplot 221,imshow(f),title('original image')
subplot 222,imhist(f),title('original Image Histogram'),ylim('auto')
subplot 223, imshow(g),title('Image after Histogram Equalization')
subplot 224, imhist(g),title('Histogram Equalization'),ylim('auto')

5
Output:

3. Homework (Enhancement Using Arithmetic Operations):


Assume you have an image for a human and you need to hide the features of the face only. Using
Matlab, develop a function that can be used to do this. (Consider '2.gif' as a mask in the attached
images carefully and used it to hide the face of '1.gif' image).

Quiz Next Week


6

S-ar putea să vă placă și