【问题标题】:How to identify non-photograph or 'uninteresting' images using Python Imaging Library (PIL)如何使用 Python 图像库 (PIL) 识别非照片或“无趣”的图像
【发布时间】:2011-02-16 01:15:30
【问题描述】:

我有数千张图片,我需要剔除那些不是照片或其他“有趣”的图片。

例如,一张“无趣”的图片可能全是一种颜色,或者大部分是一种颜色,或者是一个简单的图标/徽标。

解决方案不一定是完美的,只要足以删除最不感兴趣的图像即可。

到目前为止,我最好的想法是对像素进行随机采样,然后……对它们做点什么。

【问题讨论】:

  • 我认为最简单的方法是检查图像直方图。
  • 我是图像方面的菜鸟 - 我该如何处理直方图?

标签: python python-imaging-library imaging


【解决方案1】:

Danphe 打败了我。这是我计算图像熵的方法:

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)

【讨论】:

    猜你喜欢
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    相关资源
    最近更新 更多