function [ima1,heq] = hist_eq(ima,nb_levels)

% Creates output ideal histogram
n = nb_levels;
% Normalise it
hgram = hgram*(prod(size(ima))/sum(hgram));
m = length(hgram);
% Then Calculates histogram of original image
hist = imhist(ima,nb_levels);
% Now the cumulative histogram
cumhist = cumsum(hist);
% My Version
T = cumhist/sum(hist);
T = round(T * nb_levels) / nb_levels;
ima1 = transform(ima,T);
ima1 = uint8(ima1);
heq = imhist(ima1);

