0% found this document useful (0 votes)
45 views

Digital Image Processing

The document describes experiments conducted using MATLAB to perform digital image processing techniques on grayscale and color images. Specifically, it involves applying histogram equalization globally and locally on images, as well as two different methods for equalizing the histogram of color images - by applying it individually to the RGB color planes and by converting to HSI color space and equalizing only the intensity plane. The results are displayed and analyzed to show how the different techniques preserve or alter color information.

Uploaded by

Priyanka Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Digital Image Processing

The document describes experiments conducted using MATLAB to perform digital image processing techniques on grayscale and color images. Specifically, it involves applying histogram equalization globally and locally on images, as well as two different methods for equalizing the histogram of color images - by applying it individually to the RGB color planes and by converting to HSI color space and equalizing only the intensity plane. The results are displayed and analyzed to show how the different techniques preserve or alter color information.

Uploaded by

Priyanka Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Digital image processing (EL325)

A laboratory report submitted to


GAUHATI UNIVERSITY INSTITUTE OF SCIENCE AND TECHNOLOGY (GUIST)

GAUHATI UNIVERSITY, GUWAHATI

In partial fulfillment of the requirement for the Degree of Bachelor of Technology

In the

DEPARTMENT

OF

ELECTRONICS AND COMMUNICATION ENGINEERING

GAUHATI UNIVERSITY

Submitted by:
Priyanka Dutta(170101004)
EXPERIMENT NO.-7

AIM:

Write MATLAB code that will do the following:

Read a gray scale image and perform the following

(a) Plot histogram of the image.

(b) Equalize the histogram using normal and adaptive histogram equalization technique

(Global). Plot the s vs. r mapping.

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

This mapping is called a histogram equalization.

Global Histogram Processing

The histogram processing methods mentioned up to now are global transformation where:

 Function is designed according to the gray-level distribution over an entire image.


 Global ransformation methods may not be suitable for enhancing details over small areas.
 Where number of pixels in these small areas may have negligible influence on designing the
global transformation function.

Local Histogram Processing

It enhances details over small areas in an image.Procedure is given as follows:

 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 Equalization of grayscale image


clc;
clear all;
close all;

%% 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

1)Global Histogram Processing(Normal)


2)Global Histogram Processing(Adaptive)

3)Global Histogram Processing(Transformation)


4)Local Histogram Processing(Normal)

5)Local Histogram Processing(Adaptive)


CONCLUSION:

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:

1) Explain difference between contrast stretching & histogram equalization.

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.

Contrast stretching is not necessarily uniformly distributed.

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.

Histogram Equalization is always uniformly distributed.


EXPERIMENT NO.-8

AIM:

Write MATLAB code that will do the following:

Import a colour image and perform the following:

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

the intensity plane.

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.

Colour planes of RGB image:


Consider an RGB image array ‘I’ then,
I(:, :, 1) represents the Red colour plane of the RGB image
I(:, :, 2) represents the Green colour plane of the RGB image
I(:, :, 3) represents the Blue colour plane of the RGB image
MATLAB CODE:

%% Histogram Equalization of colour image

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

T=rgb2hsv(a); %convert to hsv image


H=T(:,:,3); %extract the value from the image
H=histeq(H); %equalize the value part
T(:,:,3)=H; %restoring the equalized image back to hsv image
rgb_new = hsv2rgb(T); %back convert the hsv image into rgb

figure,subplot(121),imshow(a),title('Original Image')
subplot(1,2,2) , imshow(rgb_new) ,title('Equalized Image using 2nd Method');

OUTPUT
FIGURE WINDOW

 1st Method- Colour information gets changed.

 2nd Method- Colour information remains as it is.


CONCLUSION:

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

equalization using two different methods?

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.

You might also like