Identifying Change: Using Image Differencing

Tonee Bayhon
3 min readFeb 1, 2021

Change is inevitable. But with so much of our world changing, it’s great if we are able to measure how much change has occurred.

In this article I will be discussing how to measure how much change has occurred to this satellite image over some months:

Satellite image from Google Earth (2015).

As with my previous articles, it is easier to look at images in ones and zeroes. Thus we will first pass a threshold to our image to get the necessary features:

from skimage.io import imread, imshow
from skimage.color import rgb2gray
img1 = rgb2gray(imread('img1.jpg'))
img1_t = 1.0 * (img1 > 0.5)
imshow(img1_t, cmap='gray');

Let us now see an image of the same area from the next available period. We will pass it through a higher threshold. This may be associated with a different color grading of the images:

img2 = rgb2gray(imread('img2.jpg'))
img2_t = 1.0 * (img2 > 0.6)
imshow(img2_t, cmap='gray');

In order for us to see which pixels are changed between these images, we perform image differencing which is simply what it is, we take the differences in the two arrays:

from skimage.util import invertdiff = img1_t - img2_t
diff_i = invert(diff)
imshow(diff_i, cmap='gray');

As we can see from the resulting image, we have gray areas which account for the ones in the inital image. We simply have to pass a threshold. This can be given to us by values of 2 in the image.

diff = img1_t - img2_t
diff_i = invert(diff) >= 2.00
imshow(diff_i, cmap='gray');

How can we empirically know how much of these changes are? We simply count the percentage of white pixels our of the total area:

(diff_i.sum()/img1.size)*100

With this, we determine the following percentage of the image has changed:

7.8459168349645285

These constitute the triangular road as well as a cleared area on the lower right:

Over the years, we can see that the area has been cleared for farming. Let’s apply the same method to determine this:

img3 = rgb2gray(imread('img3.jpg'))
img3_t = 1.0 * (img3 > 0.6)
imshow(img3_t, cmap='gray');

We then arrive with this image of the latest images’ difference:

diff = img2_t - img3_t
diff_2 = invert(diff) >= 2.00
imshow(diff_2, cmap='gray');

Again, computing for the percentage of this difference:

(diff_2.sum()/img1.size)*100

We arrive at this percentage:

33.90930039873647

From this, we can see that simply using thresholding and differencing can already determine the change in an area. Furthermore, thresholding as well inverting images can already get us the result and computation that we want.

--

--