Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am working with a python program that will check the similarity of Quora and Twitter user's profile photos, but from the result, I am not receiving a positive result when images are identical.

This is the program I have used for comparing the two images :

path_photo_quora= "/home/yousuf/Desktop/quora_photo.jpg"

path_photo_twitter="/home/yousuf/Desktop/twitter_photo.jpeg"

if open(path_photo_quora,"rb").read() == open(path_photo_twitter,"rb").read():

     print('photos profile are identical')

1 Answer

0 votes
by (108k points)

What you can do is simply work with the imagehash python module to analyze similar images.

from PIL import Image

import imagehash

hash0 = imagehash.average_hash(Image.open('quora_photo.jpg')) 

hash1 = imagehash.average_hash(Image.open('twitter_photo.jpeg')) 

cutoff = 5

if hash0 - hash1 < cutoff:

  print('images are similar')

else:

  print('images are not similar')

As the pictures are not specifically the same, there will be some variations. But imagehash will operate even if the images are resized, reduced, in different file forms, or with altered contrast or colors.

If you want to learn python then do check out the below python tutorial video for better understanding:

Browse Categories

...