# Measuring the similarity percentage between two images

Hi, what is the recommended approach to measure the percentage of similarity between images?
The use-case is extracting images from drone video and I want to select images above X percent similarity

and again, what is it for, later ?
are you trying to build a map ? track something ?

For example, suppose the drone stands still for 5 seconds, then all these frames will be classified as 100% (or close) similarity (0% of change), but if the drone continues to move, then a difference will be created, meaning a frame that part of it overlaps with the previous one but part is new, and I would like to measure the percentage of this change.
Hope I managed to explain well, thanks.

This might give you some direction: Structural similarity index measure - Wikipedia

I’ll check it out, thanks!

Hi so i try and used in this code -
from skimage.metrics import structural_similarity
import cv2

# Convert images to grayscale

first_gray = cv2.cvtColor(first, cv2.COLOR_BGR2GRAY)
second_gray = cv2.cvtColor(second, cv2.COLOR_BGR2GRAY)

# Compute SSIM between two images

score, diff = structural_similarity(first_gray, second_gray, full=True)
print(f"Similarity Score: {score * 100 :.3f}%")

on the attached photo and get - Similarity Score: 8.233%.
But I would expect to score at least 60% if not more in this case.

that’s because SSIM is not applicable here.

Can you please recommend another recommended way?

if it’s successive frames of a camera view, then the view changes gradually.

you could want to find an alignment (affine or perspective transform) and then, based on how the quads encompassing the frames overlap, evaluate intersection over union, or other measures of area.

for the alignment, you could use optical flow (dense or sparse), or feature matching. I’d recommend optical flow. low resolution frames should be good enough for your estimation. an optical flow field is quite “rich” for such a simple alignment but it’s at least giving you enough vectors and fairly robust ones at that. sparse optical flow sounds like less work. it may be faster, but need not be.

I will check this solution. Thanks you.