SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast defIEd's Avatar
    Join Date
    Feb 2005
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extract main colors from image

    Hello,

    I am looking for a script to extract the main/most used colors in an image.
    I wrote a function that uses the GD library to extract all the colors, I sort them in an array.

    The problem is, I have various sorts of blue in the array. How would I limit it to only use colors that are clearly different from each other?

    An example of a script that does what I would like to do:
    http://www.degraeve.com/color-palette/index.php

    Thank you for your reply

  2. #2
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's how I would do it. First I am guessing you are going through the image pixel by pixel. Instead of saving the colour save the number of degrees around the colour wheel. That will give you an array with 360 entries. Each time you test a colour and find the degrees increment that key by one. Once you have gone through the whole image it is simple a matter of looking for the peaks in the array.

  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imagetruecolortopalette may help you out.
    PHP questions? RTFM
    MySQL questions? RTFM


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •