Digital Image Processing
Digital Image Processing
In the
DEPARTMENT
OF
GAUHATI UNIVERSITY
Submitted by:
Priyanka Dutta(170101004)
EXPERIMENT NO.-7
AIM:
(b) Equalize the histogram using normal and adaptive histogram equalization technique
(c) Equalize the histogram using normal and adaptive histogram equalization technique
(Local).
THEORY:
Histogram:
The histogram of an image represents the relative frequency of occurrence of the various gray
level in the image.
It is denoted by h(rk)=nk, where rk is the kth gray level and nk is the number of pixels in the image
with intensity rk .
Normalized Histogram= (Total no. of pixels having intensity rk)/(Total number of pixels, n)
denoted by
P(rk) = nk/n, k=0,1,…..L-1
It is common practice to normalize a histogram by dividing each of its values by the total number
of pixels in the image(n).
P(rk) is an estimate of the probability of occurrence of gray level k.
Histogram Equalization:
Histogram equalization is the technique by which the dynamic range of the histogram of an image
is increased.
Histogram equalization assigns the intensity values of pixels in the input image such that the
output image contains a uniform distribution of intensities.
It improves contrast and the goal of histogram equalization is to obtain a uniform histogram. This
technique can be used on a whole image or just on a part of an image.
Histogram equalization spreads the grayscale values and allows one to see a larger image of
grayscale values.
The discrete form of the equalizing transformation is
sk =T(rk) =(L-1) r(rj)= j, k=0,1..L-1.
The histogram processing methods mentioned up to now are global transformation where:
Define a neighbourhood
Move it from pixel to pixel
For every pixel
- Histogram computed for the neighbourhood
- Transfer function computed for HE or H spec
- Applied on centre pixel.
MATLAB CODE:
%% Histogram Equalisation(global)
% Normal
a=imread('cameraman.tif');
[x,y]=size(a);
b=imhist(a,256);
c=histeq(a);
d=imhist(c,256);
subplot(221),imshow(a),title('Original Image');
subplot(222),imhist(a,256),title('Histogram of original image');grid on
subplot(223),imshow(c),title('Histogram Equalization(Normal)');
subplot(224),imhist(c,256),title('Histogram of equalized image');grid on
%% Adaptive
a=imread('cameraman.tif');
[x,y]=size(a);
b=imhist(a,256);
c1=adapthisteq(a);
d1=imhist(c1,256);
figure,subplot(221),imshow(a),title('Original Image');
subplot(222),imhist(a,256),title('Histogram of original image');grid on
subplot(223),imshow(c1),title('Histogram Equalization(Adaptive)');
subplot(224),imhist(c1,256),title('Histogram of equalized image');grid on
%% Transformation
a=imread('cameraman.tif');
r=0:255;
b1=imhist(a,256);
for i=1:256
Y(i)=b1(i)/(256*256);
I(i)=sum(Y)
s(i)=round(255.*I(i));
end;
figure,plot(r,s,'linewidth',2),title('Transformation(r vs s mapping)');
xlabel('Input Intensity,r')
ylabel('Output Intensity,s')
grid on
%% Histogram Equalisation(local)
%Normal
a=imread('cameraman.tif');
FUN = @histeq
G=blkproc(a,[36 36],FUN);
figure,subplot(121),imshow(a),title('Original Image');
subplot(122),imshow(G),title('Local Histogram Equalization(Normal)');
% Adaptive
FUN1 = @adapthisteq
G1=blkproc(a,[36 36],FUN1);
figure,subplot(121),imshow(a),imshow(a),title('Original Image');
subplot(122),imshow(G1),title('Local Histogram Equalization(Adaptive)')
OUTPUT
RESULTS
The above mentioned experiment was completed using the above given MATLAB code thus fulfilling
the objective. The images were displayed using the function imshow(). Here, we have performed global
and local histogram equalization techniques on a grayscale image.
VIVA QUESTIONS:
Ans:
Contrast Stretching:
Contrast stretching (often called normalization) is a simple image enhancement technique that attempts
to improve the contrast in an image by `stretching' the range of intensity values it contains to span a
desired range of values. It increases the dynamic range of the gray level.
Histogram Equalization:
Histogram equalization is the technique by which the dynamic range of the histogram of an image is
expanded. It is a technique for adjusting image intensities to enhance contrast.
AIM:
Perform histogram equalisation on the colour image by using two different methods:
(a) Apply histogram equalisation on the individual planes (R, G, B) of the colour image.
(b) Convert RGB image to HSI colour plane and perform histogram equalisation only on
THEORY:
An RGB image can be viewed as three different images(a red scale image, a green scale image and a blue
scale image) stacked on top of each other, and when fed into the red, green and blue inputs of a colour
monitor, it produces a colour image on the screen.
Histogram equalization is a non-linear process. Equalization involves intensity values of the image, not
the color components. So for a simple RGB color image, histogram equalization cannot be applied
directly on the channels. It needs to be applied in such a way that the intensity values are equalized
without disturbing the color balance of the image. Histogram Equalization can be considered as
redistribution of the intensity of the image. Color histogram equalization can be achieved by converting
a color image into HSV/HSI image and enhancing the Intensity while preserving hue and saturation
components.
clc;
clear all;
close all;
%% 1st Method
a=imread('peppers.png');
for j=1:3;
k=a(:,:,j)
k1(:,:,j)=histeq(k)
end
subplot(121),imshow(a),title('Original Image')
subplot(122),imshow(k1),title('Equalized Image using 1st method')
%% 2nd Method
figure,subplot(121),imshow(a),title('Original Image')
subplot(1,2,2) , imshow(rgb_new) ,title('Equalized Image using 2nd Method');
OUTPUT
FIGURE WINDOW
The above mentioned experiment was completed using the above given MATLAB code thus fulfilling
the objective. The images were displayed using the function imshow(). Here, we have performed global
and local histogram equalization techniques on a colour image.
VIVA QUESTIONS:
1) What is the difference between the two resultant images obtain by performing histogram
Ans:
In the first method, histogram equalization is applied on all the three planes, thus colour information
along with the intensity information gets changed which is not desirable. The proportions of various
colours are altered differently in different regions of the image.
Whereas, in the second method, the colour information remains as it is. Here, the RGB image matrix is
converted into HSI(Hue ,Saturation and Intensity) format and histogram equalization is applied only on
the Intensity matrix . The Hue and Saturation matrix remains the same. The updated HSI image matrix is
converted back to RGB image matrix.