我有数千张图像,我需要剔除那些不是照片或其他“有趣”的图像。
例如,“无趣”的图像可能全部是一种颜色,或者大部分是一种颜色,或者是简单的图标/徽标。
该解决方案不必是完美的,只要足以删除最不有趣的图像即可。
到目前为止,我最好的想法是对像素进行随机采样,然后......对它们做一些事情。
丹菲抢先了我。这是我计算图像熵的方法:
import Image
from math import log
def get_histogram_dispersion(histogram):
log2 = lambda x:log(x)/log(2)
total = len(histogram)
counts = {}
for item in histogram:
counts.setdefault(item,0)
counts[item]+=1
ent = 0
for i in counts:
p = float(counts[i])/total
ent-=p*log2(p)
return -ent*log2(1/ent)
im = Image.open('test.png')
h = im.histogram()
print get_histogram_dispersion(h)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)