Can you spot the difference? Image Differencing using Python
Can image processing techniques be used to spot the difference between two images?

Hello everyone. On some occasions, our eyes are good at spotting differences between things. But I across this link on Reader’s Digest about this difference puzzle. It was a very challenging puzzle for me. At a first glance, the images given are very identical, but by inspecting clearly, you can really see some minor differences. Instead of making my eyes tired, I used image processing techniques to spot the difference.
Image differencing is extremely useful if you want to know if there are differences between frames of your videos. The fastest way to implement this is to convert the images into grayscale and get the difference between their grayscale pixel values. If some pixels are not equal, we can say that there is a change between images.
from skimage.color import rgb2gray
from skimage.io import imread, imshow
import matplotlib.pyplot as plt
import numpy as npimage = imread('spotdiff.jpg')
image1 = image[:,:500,:]
image2 = image[:,500:,:]
image1_gray = rgb2gray(image1)
image2_gray = rgb2gray(image2)
image3 = imread('diff.jpg')
image3 = image3[:,500:,:]diff = image1_gray - image2_grayfig, ax = plt.subplots(1,4, figsize = (15,5))
ax[0].imshow(image1_gray, cmap="gray")
ax[0].set_title("First Image in Grayscale")
ax[1].imshow(image2_gray, cmap="gray")
ax[1].set_title("Second image in Grayscale")
ax[2].imshow(diff, cmap = "hsv")
ax[2].set_title("Difference in Grayscale Values")
ax[3].imshow(image3)
ax[3].set_title("Differences")
plt.tight_layout(0.1)

Here are some examples from other photos.


Thank you very much for reading. :)