Image Differencing
*image from : https://www.myhomeschoolmath.com
Back in the days when newspapers were a thing, people always go for the crossword puzzle. But for me, I quickly go to the "spot the difference" game, and as fast I can, I would search for all the difference as many as I can. Even if the game says it has ten different items, I would still look for more.
Now for this post, let's take a rest from color segmentation for our region of interest. Instead of looking for color, we will be looking at the changes of position or shapes in our images.
To quickly determine the difference between the two values, we just subtract. And that's what we will be doing on our image. But before that, as always, let's load our python libraries
import numpy as np
import matplotlib.pyplot as plt
from skimage.io import imread, imshow
from skimage.color import rgb2gray
Then let's load the two images.
Let's convert the two images to grayscale.
And as mentioned earlier, for image differencing we are just going to subtract the two images.
fig = plt.figure(figsize=(15,10))
diff = image1_gray - image2_gray
gs = fig.add_gridspec(2,2)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, :])
ax1.imshow(image1)
ax1.set_title('Image 1')
ax2.imshow(image2)
ax2.set_title('Image 2')
ax3.imshow(diff, cmap='hsv')
ax3.set_title('Differences')
plt.tight_layout()
Highlighted above are the differences between the two images.
From the apple on the upper left to the tree on the upper right will total to ten differences. If there will be hundreds of differences to determine, the next step is to do image segmentation we learned from the previous posts.
Just a quick reminder when making image differences, confirm the shape of both the images before subtracting the two.
I hope you enjoy this short post as I do.
Comments