% Title: Histogram Equalization Simulation % % Author: Ronald Bazillion % % Module Description: % % This simulation performs histogram equalization on an input image. % Histogram equalization is used in many signal processing applications % to enhance images so that certain characteristics of an image which might % have appeared too dark or too light in the original image will show up % in the enhanced image. The procedure of equalization is shown below: % % 1) Obtain the histogram of the image. % 2) Calculate the normalized sum of the histogram. This is the Cumulative % Density Function (CDF) or the Translation function T(r) % 3) Reconstruct the image using the Translation function T(r). % % The remapped intensity values are calculated by: % % k % ----- % Sk = \ Ni / N where Ni = number of occurances of intensity % / level i % ----- N = Number of pixels in image % i=0 clear NUM_OF_BITS = 8; max_value = 2^NUM_OF_BITS; % maximum value used in image input = imread('f:/ron_b/images/opajess.jpg','jpg'); %read in the image rowsize = size(input,1); colsize = size(input,2); d_input = double(input); %convert to double precision hist_data = zeros(max_value,1); %create histogram bin mp = linspace(0,1,256); %linespace used for color-mapping images mp = [mp' mp' mp']; for r = 1:rowsize %calculate global histogram of image. The bin houses for s = 1:colsize %the number of occurances of values ranged 0-255. for t = 1:max_value if (d_input(r,s) == t-1) hist_data(t) = hist_data(t) + 1; end end end end for i=1:max_value %Obtain Cumulative Density Function (CDF) if i==1 new_hist(i,1) = hist_data(i,1); else new_hist(i,1) = (new_hist(i-1,1)+ hist_data(i,1)); end end normalization = (max_value)/(rowsize*colsize); %calculate normalization new_hist = new_hist .* normalization; %normalize CDF new_hist = round(new_hist); %round CDF to nearest integer for i=1:rowsize % reconstruct new image using translation function for j = 1:colsize vector = double(input(i,j)); new_image(i,j) = new_hist(vector+1); end end %plot histograms and images figure(1),hist(d_input,max_value),title('Histogram of original image'); figure(2),hist(new_image,max_value),title('Histogram of equalized image'); figure(3),plot(new_hist),title('Plot of CDF function'); figure(4),image(input),title('original image'),colormap(mp); figure(5),image(new_image),title('equalized image'),colormap(mp); %create image file of enhanced image %new_image = uint8(new_image); %convert to unsigned 8-bit integer %imwrite(new_image,'c:/MATLABR11/bin/images/new_image.jpg','jpg');