% Unform Distribution Test for Histogram Equalization

L = 256; % intensity levels
B = (0:255)'; % bin centers
g = repmat(0:3:255,100,1); %create synthetic data uniformly distributed using repmat
% repmat: replicate and tile matrices = fun!!
[m,n] = size(g);
hcg = my_histcounts(g,B); %get histcounts
pdfg = hcg/(m*n); %pdf for g
cdfg = cumsum(pdfg); %cdf for g
ncdfg = (L-1)*cdfg; %normalized cdf

figure(1);
subplot(2,1,1); bar(B,hcg); 
title('Histograms for Synthetic Image'); xlabel('bin centers'); ylabel('counts');
subplot(2,1,2); plot(B,ncdfg,'b-',B,B,'r-'); 
legend('Uniform Distribution CDF','line y = x','Location','northwest')
title('Normalized CDF for Synthetic Image');

gp = my_histeq(g,L); %equalize histogram
hcgp = my_histcounts(gp,B);
cdfgp = cumsum(hcgp)/(m*n);
ncdfgp = (L-1)*cdfgp;

figure(2);
subplot(3,1,1); bar(B,hcg); 
title('Histograms for Synthetic Image'); xlabel('bin centers'); ylabel('counts');
subplot(3,1,2); bar(B,hcgp); 
title('Histograms for Equalized Synthetic Image'); xlabel('bin centers'); ylabel('counts');
subplot(3,1,3); plot(B,ncdfg,'b-',B,ncdfgp,'r-'); 
legend('Uniform Distribution CDF','Processed Unif Dist.','Location','northwest')
title('Normalized CDF for Processed Uniform Distribution');



