Question

i am going to develop an application for image comparison on java. For this i have choosen euclidean algorithm. This application involves with 2 images. 1. Actual image 2. Part of the actual image.

Algorithm should compare the part of the image with actual image. If the part is existed in actual image, it should return one value as matching success.

Can anyone give me the algorithmic steps? code on java will be appreciated..!

Was it helpful?

Solution

Here is a relatively simple idea, with some parts left out intentionally, since the question smells like homework.

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.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top