Dan*_*phe 6 python imaging python-imaging-library
我有成千上万的图像,我需要清除那些不是照片或其他"有趣"的图像.
例如,"不感兴趣"的图像可以是所有一种颜色,或者主要是一种颜色,或简单的图标/徽标.
解决方案不一定非常完美,只需要删除最不有趣的图像就足够了.
到目前为止,我最好的想法是对像素进行随机抽样,然后......用它们做点什么.
丹菲抢先了我。这是我计算图像熵的方法:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1532 次 |
| 最近记录: |