How to identify non-photograph or 'uninteresting' images using Python Imaging Library (PIL)
Asked Answered
C

1

6

I have thousands of images and I need to weed out the ones which are not photographs, or otherwise 'interesting'.

An 'uninteresting' image, for example, may be all one color, or mostly one color, or a simple icon/logo.

The solution doesn't have to be perfect, just good enough to remove the least interesting images.

My best idea so far is to take a random sampling of pixels, and then... do something with them.

Cellulose answered 16/2, 2011 at 1:15 Comment(2)
I think that the most simple approach is to check the image histogram.Pyrrhic
I'm a noob at image stuff - what do I do with the histogram?Cellulose
D
2

Danphe beat me to it. Here's my method for calculating image entropy:

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)
Delphinus answered 16/2, 2011 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.