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

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

问题描述

我正在运行一个 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?

推荐答案

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

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  # maximum bits that could be different between the hashes. 

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, so therefore we use a cutoff value with an acceptable maximum difference. That difference between the hash objects is the number of bits that are flipped. 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.

对于 64 位散列,0 的差异意味着散列是相同的.32 的差异意味着根本没有相似之处.64 的差异意味着一个散列是另一个的完全否定.

With 64 bit hashes, a difference of 0 means the hashes are identical. A difference of 32 means that there's no similarity at all. A difference of 64 means that one hash is the exact negative of the other.

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

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