views:

44

answers:

1

Hey, I've got so many PIL bounding box(x,y, x1,y1)

I just want to know how many colors are there in the bounding box, is there any fast way to do?

+2  A: 
>>> myimg = ...
>>> colors = myimg.crop((x0, y0, x1, y1)).getcolors()

According to PIL's docs getcolors "Returns an unsorted list of (count, color) tuples, where the count is the number of times the corresponding color occurs in the image".

pillmuncher
+1 for `crop()`, which is lazy, so, paradoxically, very fast.
Frédéric Hamidi