python怎么求app名字列相似度

Python018

python怎么求app名字列相似度,第1张

在Python中使用hnswlib算法。python求app名字列相似度在Python中使用hnswlib算法,需要导入hnswlib包。Python是一种广泛使用的高级编程语言,属于通用型编程语言,由吉多·范罗苏姆创造,发布于1991年。

就是给出以下几个function的def 越多越好:

1、 red_average(Picture) 算出pic众pixels的平均红值 。

2、scale_red(Picture, int) 调整图片红值 并确保其不超过255 。

3、expand_width(Picture, int)  。

4、reduce_width(Picture, int) 放大和缩小宽值 都是乘或者除的 ,distance(Pixel, Pixel) 以红蓝绿值为标准 计算两个pixel之间的距离(类似于xyz坐标轴中两点距离)。

5、simple_difference(Picture,Picture) 简单计算两张图片有多相似 不必考虑长宽。

6、smart_difference(Picture,Picture) 这个方程的步骤需为: 判断图片大小 。如必要 乘除高度 。 如必要 乘除宽度。 调整图片颜色使之相同平均红蓝绿值 。

Python具有丰富和强大的库。它常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。常见的一种应用情形是,使用Python快速生成程序的原型(有时甚至是程序的最终界面),然后对其中 有特别要求的部分,用更合适的语言改写,比如3D游戏中的图形渲染模块,性能要求特别高,就可以用C/C++重写,而后封装为Python可以调用的扩展类库。

from PIL import Imageimport os#import hashlib def getGray(image_file): tmpls=[] for h in range(0, image_file.size[1]):#h for w in range(0, image_file.size[0]):#w tmpls.append( image_file.getpixel((w,h)) ) return tmpls def getAvg(ls):#获取平均灰度值 return sum(ls)/len(ls) def getMH(a,b):#比较100个字符有几个字符相同 dist = 0 for i in range(0,len(a)): if a[i]==b[i]: dist=dist+1 return dist def getImgHash(fne): image_file = Image.open(fne) # 打开 image_file=image_file.resize((12, 12))#重置图片大小我12px X 12px image_file=image_file.convert("L")#转256灰度图 Grayls=getGray(image_file)#灰度集合 avg=getAvg(Grayls)#灰度平均值 bitls=''#接收获取0或1 #除去变宽1px遍历像素 for h in range(1, image_file.size[1]-1):#h for w in range(1, image_file.size[0]-1):#w if image_file.getpixel((w,h))>=avg:#像素的值比较平均值 大于记为1 小于记为0bitls=bitls+'1' else:bitls=bitls+'0' return bitls''' m2 = hashlib.md5()m2.update(bitls) print m2.hexdigest(),bitls return m2.hexdigest()'''a=getImgHash("./Test/测试图片.jpg")#图片地址自行替换files = os.listdir("./Test")#图片文件夹地址自行替换for file in files: b=getImgHash("./Test/"+str(file)) compare=getMH(a,b) print file,u'相似度',str(compare)+'%'