# -*- coding: utf-8 -*-
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
# This module can classfy the image by Average Hash Method
# The Hash Method is too strict,so this moudel suitable for finding image by Thumbnail
def getCode(img, size):
pixel = []
for x in range(0, size[0]):
for y in range(0, size[1]):
pixel_value = img.getpixel((x, y))
print pixel_value
pixel.append(pixel_value)
avg = sum(pixel) / len(pixel)
cp = []
for px in pixel:
if px > avg:
cp.append(1)
else:
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
# This module can classfy the image by Average Hash Method
# The Hash Method is too strict,so this moudel suitable for finding image by Thumbnail
def getCode(img, size):
pixel = []
for x in range(0, size[0]):
for y in range(0, size[1]):
pixel_value = img.getpixel((x, y))
print pixel_value
pixel.append(pixel_value)
avg = sum(pixel) / len(pixel)
cp = []
for px in pixel:
if px > avg:
cp.append(1)
else:

这段代码展示了如何使用Python的PIL库进行图像分析,通过平均哈希方法(Average Hash)来比较两张图片的相似度。代码首先定义了获取图片像素值并计算平均值的函数,然后使用汉明距离(Hamming distance)来比较两个哈希编码的差异。最后,`classfiy_aHash`函数用于判断两张图片是否在指定的精确度下相似。
最低0.47元/天 解锁文章
9711

被折叠的 条评论
为什么被折叠?



