在matlab中计算两个图像之间的欧几里得距离 [英] calculating Euclidean distance between two image in matlab

查看:1697
本文介绍了在matlab中计算两个图像之间的欧几里得距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab中计算两个图像之间的欧几里得距离.我找到了一些示例,并且已经尝试过,但是它们是不正确的.
欧几里得距离的结果应该在01之间,但是通过两种不同的方式,我得出了不同的解.
第一种算法给我一个4位数字,例如2000和其他这样的数字,反之,我到达了一个数字,例如0.007
怎么了

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)

推荐答案

最后一行代码需要sqrt命令:

the final line of code needs a sqrt command:

f = sum(sqrt(hn1-hn2).^2);

检查此链接

您还可以使用 norm 命令

f = norm(hn1-hn2);

这些 post1

These post1 and post2 can be useful.

这篇关于在matlab中计算两个图像之间的欧几里得距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆