【问题标题】:euclidean algorithm for image comparison图像比较的欧几里得算法
【发布时间】:2010-10-28 11:43:25
【问题描述】:

我将在 java 上开发一个用于图像比较的应用程序。为此,我选择了欧几里得算法。此应用程序涉及 2 个图像。 1. 实物图 2. 部分实物图。

算法应该将图像的一部分与实际图像进行比较。如果该部分存在于实际图像中,则应返回一个值作为匹配成功。

谁能给我算法步骤? java上的代码将不胜感激..!

【问题讨论】:

标签: java euclidean-distance image-comparison


【解决方案1】:

这是一个相对简单的想法,故意省略了一些部分,因为这个问题闻起来像家庭作业。

public static boolean contains(Image large, Image small) {
  final int largeWidth = large.getWidth(), largeHeight = large.getHeight();
  final int smallWidth = small.getWidth(), smallHeight = small.getHeight();

  if (smallWidth > largeWidth || smallHeight > largeHeight) {
    return false;
  }

  for (int x = 0; x < largeWidth - smallWidth; x++) {
    for (int y = 0; y < largeHeight - smallHeight; y++) {
      if (subImageEquals(large, x, y, small)) {
        return true;
      }
    }
  }
  return false;
}

private static boolean subImageEquals(Image large, int x, int y, Image small) {
  // TODO: checks whether all pixels starting at (x, y) match
  // those of the small image.
}

【讨论】:

  • subImageEquals 应该返回 double 以表示相似性,因为由于压缩和其他因素噪声等原因,两个图像对于所有像素并不相等。相反,您应该像相关算法一样计算相似度。
  • @schoetbi:是的,subImageEquals 应该返回双精度类型值。 @Roland Illig:我们可以应用最大公约数(GCD)吗?
  • 我不明白 GCD 与比较图像有什么关系。你能再解释一下吗?
  • GCD 就像区域之间的欧几里得距离。
  • 实际上,我正在拍摄 A 和 B 之类的两张图像来相互比较。我认为最好为每张图像取 25 个区域。然后计算区域之间的距离会很好。欧几里得算法是寻找 GCD 的最佳方法。 GCD 用于测量两个区域之间的距离..!
猜你喜欢
  • 2016-06-19
  • 1970-01-01
  • 1970-01-01
  • 2018-07-30
  • 1970-01-01
  • 2016-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多