Hello Will,
Friday, November 26, 2004, 7:48:08 PM, you wrote:
> Laszlo Zsolt Nagy wrote:
>> Hello,
>>
>> How can I determine the number of colors used in an image? I tried to
>> search on Google but I could figure out. I read the PIL handbook but I
>> do not see how to do it. Can anyone help?
> You may get a better response on how to do it in Python, but the
> following C++ code should be easy to translate if necessary. All it
> requires is a get pixel function.
> int CImage::CountUsedColours() const
.....
> Regards,
> Will McGugan
Yes, this can be efficient in C++. I'm not sure but possible it is not
so efficient in Python. Also it would be far better to have direct
access to the pixels (and not using a method/function). Now I'm
thinking about ImageMagick and something like this:
f = os.popen('identify -verbose ' + fullpath + ' | grep -e "Colors:"')
s = f.read()
index = s.find(':')
color_count = long( (s[index+1:]).strip() )
Probably ImageMagick uses direct access to pixels but it still take
seconds to run. It is not that portable but I'll stay at this version.
Thank you very much.
--
Best regards,
Laszlo
private.php?do=newpm&u=
web:
http://designasign.biz