%
% JohnnyEQ.m
%
% 04/03/03 jph
%
% 02/12/14: update full-scale contrast stretch part of histogram
%           equalization algorithm to match new notes. jph.
%


xsize = 256;


%
% Read and display the image
%
x = ReadBin('johnny.bin',xsize);
figure(1);colormap(gray(256));
image(x);axis('image');
title('Original johnny.bin Image','FontSize',12);
print -deps MjohnnyCrop.eps;
print -dpdf Mjohnny.pdf;

%
% Show the histogram of the original image
%
figure(2);
bar(sum(hist(x,0:255)'));
title('Original Johnny Histogram','FontSize',12);
axis([0 256 0 2500]);
set(gca,'XTick',[0:16:256]);
set(gca,'YTick',[0:250:2500]);
print -deps MjohnnyOrigHistCrop.eps;
print -dpdf MjohnnyOrigHist.pdf;

%
% Perform histogram equalization
%
y = HistEQ(x);

%
% Display the new image and show its histogram
%
figure(3);colormap(gray(256));
image(y);axis('image');
title('Histogram Equalized Johnny Image','FontSize',12);
print -deps MjohnnyEQCrop.eps;
print -dpdf MjohnnyEQ.pdf;

figure(4);
bar(sum(hist(y,0:255)'));
title('Equalized Histogram of Johnny','FontSize',12);
axis([0 256 0 2500]);
set(gca,'XTick',[0:16:256]);
set(gca,'YTick',[0:250:2500]);
print -deps MJohnnyEQHistCrop.eps;
print -dpdf MJohnnyEQHist.pdf;
