Histogram Equalization Algorithm Implementation Using MATLAB

  Histogram equalization is a method in image processing of contrast adjustment using the image's histogram. The histogram of a digital image is a distribution of its discrete intensity levels in the range [0,L-1]. The distribution is a discrete function h associating to each intensity level: rk the number of pixel with this intensity: nk.

Normalization of a Histogram

Normalize an histogram is a technique consisting into transforming the discrete distribution of intensities into a discrete distribution of probabilities. To do so, we need to divide each value of the histogram by the number of pixel. Because a digital image is a discrete set of values that could be seen as a matrix and it's equivalent to divide each nk by the dimension of the array which is the product of the width by the length of the image.

 

Equalization of a Histogram

Histogram equalization is a method to process images in order to adjust the contrast of an image by modifying the intensity distribution of the histogram. The objective of this technique is to give a linear trend to the cumulative probability function associated to the image.




New Probability Density Function

 

MATLAB CODE:
clear all;
close all;
im=rgb2gray(imread('peppers.png'));
[l,m]=size(im);
histogram=zeros(256,1);

% Calculating Pixel Level Occurance (Histogram)
for i=1:l
    for j=1:m
        value=im(i,j);
        histogram(value)=histogram(value)+1;
    end
end

% Normalized Histogram
pdf=histogram/(l*m);
stem(1:size(histogram),pdf);
figure, imhist(im);

cum_sum=0;

% cumulative distribution function
for i=1:size(pdf)
    cum_sum=cum_sum+pdf(i);
    cum_sum_vec(i)=cum_sum;
    cdf(i)=round(cum_sum_vec(i)*255);
end

figure,stem(1:size(histogram),cdf);


% Histogram Equalization
for i=1:l
    for j=1:m
        Output(i,j)=cdf(im(i,j)+1);
    end
end

figure;
subplot(1,2,1), imshow(im);
subplot(1,2,2),imshow(uint8(Output));
figure, imhist(uint8(Output));

Comments

Popular posts from this blog

Electrophoretic Display

Color Electrophoretic Display