# Compare image similarity in Python

I'm using a dataset of movies and would like to group if a movie is the same across different retailers.

Example:

Movie: Beauty and the Beast

Platforms: Google, Netflix, iTunes, Amazon.

I have access to signals like: Studio, Movie Name, Runtime, Language, Release Year, etc. However, in this case some movies, which are not the same and signals mentioned before, are not capable of finding the right match. I need to do what a human would do: Check Movie cover. Example:

I have access to the art image. I'm using Python to do this comparison.

Is there a library that can help me compare 2 images and determine if they are similar?

The problem you mention is not trivial. There is no library that out of the box will compare the pictures for you and give you a reliable similarity value. Therefore, you need to develop a system that works for both your problem and your dataset.

Having said that, since neural networks work better than any other method for image recognition you can try:

• Autoencoders: (In case your data is unlabeled) The idea is that the model extracts the features for you and then you omit the output layers so you have a new representation of your image but in a new feature space the model has learnt from data. Once your images are in this new feature space, you can use whatever technique to compute similarity. You can have an example on how to do this here.

• Hash binary codes: (In case your data is labeled). This is a supervised method based on CNNs that seems to work quite nice to find relevant features in your images. Have a look at this paper.

Working with images is normally not quite straighforward and it requires some effort and experimentation to master these techniques. However, it is absolutely worth it and fun.

You can use ImageHash

The difference between the hashed images will give you a similarity score

from PIL import Image
import imagehash

hash = imagehash.average_hash(Image.open('test.png'))
otherhash = imagehash.average_hash(Image.open('other.bmp'))

print(hash - otherhash)


https://pypi.org/project/ImageHash/