How to check similarity of two images that have different pixelization

后端 未结 2 2185
太阳男子
太阳男子 2021-02-07 12:41

I am running a python code to check similarity of Quora and Twitter users profiles photos, but i am not getting a positive result when images are the same.

This is the c

相关标签:
2条回答
  • 2021-02-07 13:30

    You can use the imagehash library to compare 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')
    

    Since the images are not exactly the same, there will be some differences. But imagehash will work even if the images are resized, compressed, different file formats or with adjusted contrast or colors.

    The hash (or fingerprint, really) is derived from a 8x8 monochrome thumbnail of the image. But even with such a reduced sample, the similarity comparisons give quite accurate results. Adjust the cutoff to find a balance between false positives and false negatives that is acceptable.

    0 讨论(0)
  • 2021-02-07 13:44

    The two images are NOT the same - only the thing imaged. The images obviously are different size, as you note yourself. Thus a comparison must fail.

    You'll need to employ some kind of similarity check. The first step is to scale up the smaller image to the one of the larger one. Then you need to employ some mean of detecting and defining similarity. There are different ways and methods for that, and any combination of them might be valid.

    For example see Checking images for similarity with OpenCV

    0 讨论(0)
提交回复
热议问题