% histogram equalization


function G = my_histeq(F,L)

[M,N] = size(F); 
B = (0:L-1)'; %bin centers, ' <--- means transpose to column vector (matlab tutorial!)
n = my_histcounts(F,B); %get histcounts
G = F; % initialize G to F

T = round(((L-1)/(M*N))*cumsum(n)); %calculate transform

for i=1:M
   for j=1:N
        G(i,j) = T(F(i,j)+1); %transform intensities
   end
end

%G(:,:) = T(F(:,:)+1); % vectorize the loop

G = uint8(G); %convert back to uint8 since 8-bit image








