Image spot detection in Python
Question: I have millions of images containing every day photos. I'm trying to find a
way to pick out those in which some certain colours are present, say, red and
orange, disregarding the shape or object. The size may matter - e.g., at least
50x50 px.

Is there an efficient and lightweight library for achieving this? I know there
is OpenCV and it seems quite powerful, but would it be too bloated for this
task? It's a relatively simple task, right?

Thanks


Answer: Certainly OpenCV can do this, but you could also use the Python Imaging
Library [PIL](http://www.pythonware.com/products/pil/) and just create a
function to iterate through the image cropping small blocks of the image set
at your minimum size, and testing these blocks average colour and tolerance
against the matching criteria. Something along the lines of (untested pseudo
code):

    
    
    import Image
    
    im = Image.open("test_picture.png")
    for y in xrange(image_height - block_height):
        for x in xrange(image_width - block_width):
            block = im.crop(x, y, x + block_width, y + block_height)
            if colour_test(block):   # test for match
                return True
    

Its very easy to get the colour frequency info of an image using
`block.getcolors()`, so you can easily write the `colour_test()` function.

