Sei sulla pagina 1di 3

Experiment Number 4

Experiment Title Implementation of Histogram Equalization


Resources / Apparatus Hardware: Software:
Required Computer system Octave/Matlab
Theory Histogram equalization is a straightforward image-processing
technique often used to achieve better quality images in black and
white color scales in medical applications such as digital X-rays,
MRIs, and CT scans.

A digital image is a binary representation of a two-dimensional


image. The digital representation is an array of picture elements
called pixels. Each of these pixels has a numerical value which in
monochromatic images represents a grey level.

Basically the histogram equalization spreads out intensity values


along the total range of values in order to achieve higher contrast.
This method is especially useful when an image is represented by
close contrast values, such as images in which both the
background and foreground are bright at the same time, or else
both are dark at the same time.

The general approach for cumulative histogram equalization is


described. Here are the steps for implementing this algorithm.
1. Create the histogram for the image.
2. Calculate the cumulative distribution function histogram.
3. Calculate the new values through the general histogram
equalization formula.
4. Assign new values for each gray value in the image.

Program Histogram Equalization:


close all;
clear all;
clc
GIm=imread('cameraman.tif');
numofpixels=size(GIm,1)*size(GIm,2);
figure,imshow(GIm);
title('Original Image');
HIm=uint8(zeros(size(GIm,1),size(GIm,2)));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
n=1:256;
%freq counts the occurrence of each pixel value.
%The probability of each occurrence is calculated by probf.
for i=1:size(GIm,1)
for j=1:size(GIm,2)
value=GIm(i,j);
freq(value+1)=freq(value+1)+1;
probf(value+1)=freq(value+1)/numofpixels;
end
end
figure,stem(n,probf);
title('Probability Distribution Function')
sum=0;
no_bins=255;
%The cumulative distribution probability is calculated.
for i=1:size(probf)
sum=sum+freq(i);
cum(i)=sum;
probc(i)=cum(i)/numofpixels;
output(i)=round(probc(i)*no_bins);
end
figure,stem(n,output);
for i=1:size(GIm,1)
for j=1:size(GIm,2)
HIm(i,j)=output(GIm(i,j)+1);
end
end
figure,imshow(HIm);
title('Histogram equalization');
Output Output Histogram Equlization:

Potrebbero piacerti anche