views:

42

answers:

1

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

A: 

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.
}
Roland Illig
subImageEquals should return double for similarity since due to compression and other things noise, etc. two images are not equal for all pixels. Rather you should compute a similarity like in the correlation algorithm.
schoetbi
@schoetbi: yes, subImageEquals should return double type value. @Roland Illig: Do we can apply Greatest common devisor (GCD) ?
hemanth
I don't understand what the GCD has to do with comparing images. Can you explain that a bit more?
Roland Illig