Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing similar images as photographs -- detecting difference, image diff

The situation is kind of unique from anything I have been able to find asked already, and is as follows: If I took a photo of two similar images, I'd like to be able to highlight the differing features in the two images. For example the following two halves of a children's spot the difference game:

left half of spot the differenceright half of spot the difference

The differences in the images will be bits missing/added and/or colour change, and the type of differences which would be easily detectable from the original image files by doing nothing cleverer than a pixel-by-pixel comparison. However the fact that they're subject to the fluctuations of light and imprecision of photography, I'll need a far more lenient/clever algorithm.

As you can see, the images won't necessarily line up perfectly if overlaid.

This question is tagged language-agnostic as I expect answers that point me towards relevant algorithms, however I'd also be interested in current implementations if they exist, particularly in Java, Ruby, or C.

like image 252
Mike Campbell Avatar asked Apr 09 '13 18:04

Mike Campbell


1 Answers

The following approach should work. All of these functionalities are available in OpenCV. Take a look at this example for computing homographies.

  • Detect keypoints in the two images using a corner detector.
  • Extract descriptors (SIFT/SURF) for the keypoints.
  • Match the keypoints and compute a homography using RANSAC, that aligns the second image to the first.
  • Apply the homography to the second image, so that it is aligned with the first.
  • Now simply compute the pixel-wise difference between the two images, and the difference image will highlight everything that has changed from the first to the second.
like image 60
Zaphod Avatar answered Sep 19 '22 12:09

Zaphod