I want to calculate the Euclidean distance between two images in Matlab. I find some examples and I've try them but they are not correct.
The result of this Euclidean distance should be between 0 and 1 but with two different ways I reached to different solutions.
The first algorithm gives me a 4 digit number such as 2000 and other digits like this and by the other way I reached numbers such as 0.007
What is wrong with it?
This is one of those algorithms I mentioned:
Im1 = imread('1.jpeg');
Im2 = imread('2.jpeg');
Im1 = rgb2gray(Im1);
Im2 = rgb2gray(Im2);
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
% Calculate the Euclidean distance
f = sum((hn1 - hn2).^2)
解决方案
the final line of code needs a sqrt command:
f = sum(sqrt(hn1-hn2).^2);
check this link
You can also use the norm command
f = norm(hn1-hn2);
These post1 and post2 can be useful.