如何检查像素化不同的两个图像的相似性 [英] How to check similarity of two images that have different pixelization

查看:250
本文介绍了如何检查像素化不同的两个图像的相似性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行python代码来检查Quora和Twitter用户个人资料照片的相似性,但是当图像相同时我没有得到肯定的结果.

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 code 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')

尽管图像相同,但控制台未打印照片配置文件相同",我该怎么办?

despite images are the same, the console is not printing "photos profile are identical", what can i do?

推荐答案

您可以使用图像哈希库以比较相似的图像.

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')

由于图像不完全相同,因此会有一些差异.但是,即使重新调整图像大小,压缩图像,使用不同的文件格式或调整了对比度或颜色,imagehash仍然可以使用.

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.

哈希(实际上是指纹)是从图像的8x8单色缩略图派生的.但是,即使样本量减少了,相似度比较也可以得出非常准确的结果.调整截止值,以在假阳性和假阴性之间找到一个可以接受的平衡点.

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.

这篇关于如何检查像素化不同的两个图像的相似性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆