% Function: Calculate the normalized histogram of an image.
% Prameter:
% Input:
% im: gray image with gray level 0-255(must be gray image)
% Output:
% h_nor: normalized histogram(possibilities)
% Author: ZhouJingjin
% Version: 1.0
function h_nor = histogram(im)
[M,N] = size(im);
h = zeros(1,256); %gray level: 0-255
for i = 1:M
for j = 1:N
h(im(i,j)+1) = h(im(i,j)+1) + 1; %calculate the number of pixels for each gray level
end
end
h_nor = h / (M*N); %normalized histogram
% Function: Implement the histogram equalization technique to an image.
% Prameter:
% Input:
% im: Gray image with gray level 0-255(must be gray image)
% Output:
% im_conv: Enhanced image
% his_conv: normalized histogram(possibilities) of the enhanced
% image:use for plotting the histogram-equalization(s_k versus r_k)
% conv_table:
% Author: ZhouJingjin
% Version: 1.0
function [his_conv, im_conv, conv_table] = his_equ(im)
his = histogram(im);
cdf = cumsum(his);
conv_table = round(cdf * 255);
[M,N] = size(im);
im_conv = zeros(M,N);
for i = 1:M
for j = 1:N
im_conv(i,j) = conv_table(im(i,j) + 1);
end
end
im_conv = uint8(im_conv);
his_conv = histogram(im_conv);