At some point,
(Larry) wrote:
> (Larry) wrote in message news:<. com>...
>> I've been walking up, down, and around instances in the object model
>> of PIL trying to figure out how to easily calculate how many unique
>> colors are used in an image, specifically a bitmap (mode "P"). Am I
>> missing something?
>>
>> Thanks python friends!
>
> So far I have: colors=len(sets.Set(list(im.getdata())))
>
> That makes me want to throw up.
Probably very inefficient. Have a look at im.histogram(). Something
like:
colours = sum( [ 1 for h in im.histogram() if h != 0 ] )
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca