0

I have two images with common background and the only differences between them are the moving circles.

Image 1:

enter image description here

Image 2:

enter image description here

Expected Difference Image is something like this:

enter image description here

As you can see, the differences are highlighted with the image numbers.

All I was able to do for now is:

import cv2

img1 = cv2.imread("1.jpg", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("2.jpg", cv2.IMREAD_GRAYSCALE)
diff = cv2.absdiff(img1, img2)

Is there any way to do this? Any help would be appreciated!

ham
  • 716
  • 5
  • 12

1 Answers1

0

You could compare the pixels one by one with a library like PIL.

When a pixel has the same color in both images, just draw it. When you come to a pixel which value is the background color in one image but not in the other, draw the pixel that is non-background color.

This is a very basic idea, that ought to be improved, though. For instance, what if the shapes overlap? But then, you will want to detect the edges, and fall into the field of signal processing, which is a lot more complex. But nothing is impossible! Just more difficult.

Right leg
  • 16,080
  • 7
  • 48
  • 81