当我们要用一张图片跟大量图片对比寻找最相似(最小欧几里得距离等)时用本文的方法能减少内存使用量加快运算速度。
优化的欧几里得距离计算方法:
function d = EuclideanDistance(a,b)
% DISTANCE - computes Euclidean distance matrix
%
% E = EuclideanDistance(A,B)
%
% A - (MxD) matrix
% B - (NxD) matrix
%
% Returns:
% E - (MxN) Euclidean distances between vectors in A and B
%
%
% Description :
% This fully vectorized (VERY FAST!) m-file computes the
% Euclidean distance between two vectors by:
%
% ||A-B|| = sqrt ( ||A||^2 + ||B||^2 - 2*A.B )
%
% Example :
% A = rand(100,400); B = rand(200,400);
% d = EuclideanDistance(A,B);
% Author : Roland Bunschoten
% University of Amsterdam
% Intelligent Autonomous Syst