Wednesday, July 25, 2012

Histogram Equalization

  Histogram Equalization is a popular technique for enhancing image contrast. Histogram Equalization can change in image brightness that is become much brighter than input image. Histogram Equalization has been a simple effective image enhancement technique but Histogram Equalization tends to change the brightness of an image significant, causing unnatural contrast enhancement. Besides that, Histogram Equalization is not commonly used on scanning electron microscope (SEM) image this method causes significant change on the input image brightness and introduce undesirable artifacts. The mean brightness Histogram Equalization image is always the middle gray level regardless of the input image mean, thus this characteristic is not desirable in application where brightness preservation is needed. As a result, Histogram Equalization is not commonly used in consumer electron because it could cause annoying distortions like excessive brightness change, noise artifacts and brightness saturation.

Source Code
Matlab version R2011b (7.13.0.564)

%original Image
originalImage=imread('cameraman.tif');

%define the size of image after Histogram Equalization
HEImage=uint8(zeros(size(originalImage,1),size(originalImage,2)));

%calculate total pixels of original image
numofpixels=size(originalImage,1)*size(originalImage,2);

%obtain intensity by using imhist
[intensity grayLevels]=imhist(originalImage);

%calculate the pdf of original image
pdf=intensity/numofpixels;

%calculate the cdf of original image
cdf=cumsum(pdf);

%convert to Histogram Equalization image by replace the pixels of original image
for i=1:size(originalImage,1)
    for j=1:size(originalImage,2)
        HEImage(i,j)=round(cdf(originalImage(i,j)+1)*255);
    end
end

%showing and plotting the original image and image after Histogram Equalization
subplot (2,2,1);
imshow(originalImage);
title('Original Histogram');
subplot (2,2,2);
imhist(originalImage);
subplot (2,2,3);
imshow(HEImage);
title('Histogram equalization');
subplot (2,2,4);
imhist(HEImage);


Result: 
Histogram Equalization
Before and After Histogram Equalization

No comments:

Post a Comment