代码之家  ›  专栏  ›  技术社区  ›  janasainik

图像比较的欧氏算法

  •  0
  • janasainik  · 技术社区  · 14 年前

    我将在java上开发一个图像比较应用程序。为此,我选择了欧几里德算法。此应用程序包含两个图像。 一。实际图像 2。实际图像的一部分。

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

    有人能给我算法步骤吗?java代码将不胜感激。。!

    1 回复  |  直到 14 年前
        1
  •  0
  •   Roland Illig    14 年前

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

    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.
    }