function [histdist] = histogramDistance(im1, im2)
    %Compares using the Euclidean distance of the images' histograms.
    %This divides by the maximum frequency in the histogram to obtain
    %relative frequencies, rather than an absolute number of pixels.
    %This yields a better average correlation between the histograms.
    
    %im2double doesn't work on grayscale images?
    im1 = im1 ./ max(im1(:));
    im2 = im2 ./ max(im2(:));
    
    %Since all differences are at most 1, the maximum sum of differences is
    %256. We take the square root, and thus the maximum distance is 16.
    %To normalize the distance, we simply divide.
    histdist = norm((imhist(im1) / max(imhist(im1))) - (imhist(im2) / max(imhist(im2)))) ./ 16;
    %histdist = norm(imhist(im1) - imhist(im2)); %Old method
end