我有两张图片,假设分别为
P
和S
,大小均为8192×200,我想计算它们之间的自定义“欧几里得距离”。目前我使用以下步骤:
Reshape the images into a pair of column and row vectors:
Ip = Ip(:).'; Is = Is(:);
Calculate a metric matrix,
G
, whose entries are given by the formulaG(i,j) = 1/(2*pi*r*r) * exp((-d*d)/(2*r*r));
where
r
is a global parameter that varies from 0 to 20, say, andd
is the distance between pixeli
and pixelj
. E.g., if pixeli
is(k,l)
and pixelj
is(k1,l1)
, thend = sqrt((k-k1)^2 + (l-l1)^2);
. Pixel 1 will be(1,1)
, Pixel 2 will be(1,2)
, and so on. Therefore, the size of matrixG
will be1638400×1638400
.Compute the final (scalar) Euclidean distance between two images, using:
ImEuDist = sqrt( (Ip-Is) * G * (Ip-Is).' );
请帮助我优化这个程序;我希望它能在几秒钟内运行。请注意,我不对涉及GPU的解决方案感兴趣。
Ip
和Is
都是行向量或列向量。这不包括Ip
是行向量而Is
是列向量以及反之的情况。 - nagarwal