怎样计算两张图片的相似度

自己写的得到感知哈希字符串的程序#-*- coding:utf-8 -*-import osfrom PIL import Imageimport numpy as npdef getImage():\tFindPath="./" \tfilenames=os.listdir(FindPath) \tfor name in filenames: \t filePath=os.path.join(FindPath,name) \t print(filePath)\t myhash=dhash(filePath)\t print myhash f = open(\u0026#39;hash.txt\u0026#39;, \u0026#39;w\u0026#39;) f.write(myhash+\u0026#39;\\u0026#39;)def dhash(imagename,hash_size = 8): openname=imagename img = Image.open(openname) image=img # Grayscale and shrink the image in one step. image = image.convert(\u0026#39;L\u0026#39;).resize((hash_size + 1, hash_size),Image.ANTIALIAS,) pixels = list(image.getdata()) # Compare adjacent pixels. difference = for row in xrange(hash_size): for col in xrange(hash_size): pixel_left = image.getpixel((col, row)) pixel_right = image.getpixel((col + 1, row)) difference.append(pixel_left \u0026gt; pixel_right) # Convert the binary array to a hexadecimal string. decimal_value = https://www.zhihu.com/api/v4/questions/35724543/0 hex_string = for index, value in enumerate(difference): if value: decimal_value += 2**(index % 8) if (index % 8) == 7: hex_string.append(hex(decimal_value).rjust(2, /u0026#39;0/u0026#39;)) decimal_value = 0 return /u0026#39;/u0026#39;.join(hex_string)if __name__ == /u0026#39;__main__/u0026#39;:/tgetImage()和计算感知哈希距离的函数def OsDistance(vector1, vector2): sqDiffVector = vector1-vector2 sqDiffVector=sqDiffVector**2 sqDistances = sqDiffVector.sum() distance = sqDistances**0.5 return distance通过感知哈希距离可以大概得到相似度
■网友
图像感知哈希算法,SIFT/SURF,HOG。PS:我只用过SIFT.....
■网友
compare image1 image2 diff


    推荐阅读