I have no idea what it is you call axis. Anyway, I don't see what the problem is with writing a loop a that compare your image to a set of images:
templatefiles = dir(fullfile(yourtemplatefolder, '*.png'));
hammingdistances = zeros(size(templatefiles));
for fileidx = 1:numel(templatefiles)
templateimage = imread(fullfile(yourtemplatefolder, templatefiles(fileidx).name));
hammingdistances(fileidx) = hammingdist(yourimage, templateimage);
end
A few things about your hammingdist function:
- It only works on greyscale images (or it only computes the distance between the red channels)
- It assumes both images are exactly the same size but never checks that it is the case
- It does not use the ability of matlab to operate directly on matrices. Your whole function can be achieved with just one line of code (three if you add the above checks):
function [hd]=hammingdist(image1,image2)
assert(isequal(size(image1) == size(image2), 'images are not the same size');
assert(ndims(image1) == 2, 'images are not greyscale');
hd = sum(image1(:) ~= image2(:)) / (2 * numel(image1));
end
- Oh, and don't use sum as a variable name since it prevents you from using the very useful sum function (as used above).