2011-02-16 46 views
5

我有成千上萬的圖像,我需要清除那些不是照片或其他「有趣」的圖像。例如,「無趣」圖像可以全部是一種顏色,或者大多是一種顏色,或者是簡單的圖標/標誌。如何使用Python成像庫(PIL)識別非照片或「無趣」圖像

該解決方案不一定非常完美,只需移除最不感興趣的圖像即可。

我到目前爲止最好的想法是採取像素的隨機採樣,然後...做些什麼與他們。

+1

我認爲最簡單的方法是檢查圖像直方圖。 – Tarantula 2011-02-16 01:17:44

回答

2

丹菲打敗了我。這裏是我的圖像熵計算方法:

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)