Re: Dominant color & PIL

Discussion in 'Python' started by Fredrik Lundh, Jan 24, 2006.

  1. Sebastjan Trepca wrote:

    > I was wondering is it possible to find out which colour is dominant in an
    > image using PIL?
    > It would be very easy to create interesting mozaic images with that :)


    some alternatives:

    >>> i = Image.open(...)


    >>> i.quantize(1).convert("RGB").getpixel((0, 0))

    (208, 205, 202)

    >>> import ImageStat
    >>> s = ImageStat.Stat(i)
    >>> s.mean

    [208.32295432458699, 204.56614188532555, 202.44663427275671]

    >>> i.resize((1, 1), Image.ANTIALIAS).getpixel((0,0))

    (212, 212, 210)

    (quantize will only return colors that actually exist, the other two
    uses different ways to calculate some kind of average color)

    </F>
    Fredrik Lundh, Jan 24, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shelly
    Replies:
    2
    Views:
    551
    Marco Schmidt
    Jan 8, 2004
  2. Terry Hancock

    Re: Dominant color & PIL

    Terry Hancock, Jan 23, 2006, in forum: Python
    Replies:
    2
    Views:
    540
    Terry Hancock
    Jan 23, 2006
  3. Sverre
    Replies:
    2
    Views:
    3,548
    Sverre
    Dec 17, 2009
  4. Robert Oschler

    Dominant O/S for Japanese Ruby users?

    Robert Oschler, Jun 16, 2004, in forum: Ruby
    Replies:
    3
    Views:
    101
    Alexander Kellett
    Jun 17, 2004
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    410
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page