0% found this document useful (0 votes)
51 views6 pages

DIP - Experiment No.4

Histogram equalization is used to enhance contrast in images. It transforms the intensity values of pixels to produce an output image with a uniform histogram. The algorithm calculates the probability density function and cumulative density function of the input image histogram. It then maps the input gray levels to new output gray levels using these functions. When implemented in MATLAB, the histeq function performs histogram equalization automatically. Alternatively, it can be implemented manually by calculating frequencies, probabilities, and cumulative sums to determine the mapping from input to output pixel values. The results show that histogram equalization improves contrast and detail in dark, bright, or low contrast images by redistributing pixel intensities across the full range.

Uploaded by

mayuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

DIP - Experiment No.4

Histogram equalization is used to enhance contrast in images. It transforms the intensity values of pixels to produce an output image with a uniform histogram. The algorithm calculates the probability density function and cumulative density function of the input image histogram. It then maps the input gray levels to new output gray levels using these functions. When implemented in MATLAB, the histeq function performs histogram equalization automatically. Alternatively, it can be implemented manually by calculating frequencies, probabilities, and cumulative sums to determine the mapping from input to output pixel values. The results show that histogram equalization improves contrast and detail in dark, bright, or low contrast images by redistributing pixel intensities across the full range.

Uploaded by

mayuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No.

: 04 Date of Performance:
Date of Submission:

AIM: To perform histogram equalization of a bad quality image and observe the difference
A. using Standard Matlab Function. B. Without using Standard Matlab Function.

REQUIEMENTS: PC with MATLAB software, Printer.


THEORY: Histogram Equalization-
Histogram is defined as probability density function which gives probability of occurrence of
each gray level.
P(rk) = nk / n

n=number of pixels with k gray levels/total number of pixels. Figure 1 shows histogram of dark
bright low contrast and high contrast image.

Histogram equalization is a spatial domain method that produces output image with uniform
distribution of pixel intensity means that the histogram of the output image is flattened and
extended systematically. We acquire the probability density function (PDF) and cumulative
density function (CDF) via the input image histogram. Apply these two functions PDF and CDF
for replacing the input image gray levels to the new gray levels, and then we generate the
processed image and histogram for the resultant image. And when we discriminate input image
histogram with the processed image histogram we found that the gray level intensities are
stretched and depressed systematically.

The process of adjusting intensity values can be done automatically by the “HISTEQ” function.
“HISTEQ” performs histogram equalization, which involves transforming the intensity values so
that the histogram of the output image approximately matches a specified histogram.
Fig. 2 Histograms of images a) Dark b) Bright c) low contrast d) high contrast

Fig. 2Block Diagram

Various MATLAB Functions Used: -


1) IMHIST
Display a histogram of image data
Syntax
imhist(I,n)
imhist(X,map)
Description
imhist(I) displays a histogram for the intensity image I above a grayscale colorbar. The number
of bins in the histogram is specified by the image type. If I is a grayscale image, imhist uses a
default value of 256 bins. If I is a binary image, imhist uses 2 bins.
imhist(I,n) displays a histogram where n specifies the number of bins used in the histogram. n
also specifies the length of the colorbar. If I is a binary image, n can only have the value 2.
imhist(X,map) displays a histogram for the indexed image X. This histogram shows the
distribution of pixel values above a colorbar of the colormap map. The colormap must be at least
as long as the largest index in X. The histogram has one bin for each entry in the colormap.

2) HISTEQ
Enhance contrast using histogram equalization
Syntax
J = histeq(I,hgram)
J = histeq(I,n)
[J,T] = histeq(I,...)
Description
histeq enhances the contrast of images by transforming the values in an intensity image, or the
values in the colormap of an indexed image, so that the histogram of the output image
approximately matches a specified histogram. J = histeq(I,hgram) transforms the intensity image
I so that the histogram of the output intensity image J with length(hgram) bins approximately
matches hgram.
J = histeq(I,n) transforms the intensity image I, returning in J an intensity image with n discrete
gray levels.
[J,T] = histeq(I,...) returns the grayscale transformation that maps gray levels in the intensity
image I to gray levels in J.

ALGORITHM:

scan the input image


-Perform histogram equalization using transformation
S=T(r)
-Plot histogram equalization transformation function
-display the input and output image
-Plot histogram for input and output image.

PROGRAM:
A. Using Standard Matlab Function.
clc;
clear all;
disp('Histogram Equalization of image')
I = imread('shadow.tif')
imview(I)
figure,imhist(I)
J=histeq(I)
imview(J)
figure,imhist(J)
[J,T] = histeq(I)
figure,plot((0:255)/255,T)

B. Without using Standard Matlab Function.


I=imread('tire.tif');
figure(1),imshow(I);
figure(2),imhist(I);
L=255;
J=uint8(zeros(size(I,1),size(I,2)));
[r,c]=size(I);
n=r*c;
freq=zeros(256,1);
pdf=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
disp('n=');
disp(n)
for i=1:r
for j=1:c
value=I(i,j);
freq(value+1)= freq(value+1)+1;
pdf(value+1)= freq(value+1)/n;
end
end
sum=0;
for i=1:size(pdf)
sum=sum+freq(i);
cum(i)=sum;
cdf(i)=cum(i)/n;
output(i)=round(cdf(i)*L);
end
for i=1:size(I,1)
for j=1:size(I,2)
J(i,j)=output(I(i,j)+1);
end
end
figure(3),imshow(J);
figure(4),imhist(J);
RESULT: The results are shown:
B. Without using Standard Matlab Function.

CONCLUSION: It is observed that by histogram equalization, a dark image, a bright image or a


low contrast image is modified so as to bring out the details lost in the image. Histogram
equalization redistributes the pixels over the entire pixel range. Thus it provides a proper image
with a better dynamic range.

SIGNATURE & REMARKS:

Assignment: Execute the programs and upload results and


conclusion in PDF format.

You might also like