Created
November 9, 2012 06:05
-
-
Save joshsmith/4043993 to your computer and use it in GitHub Desktop.
Getting the 8 most frequent colors from an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| image = Magick::Image.read("https://s3.amazonaws.com/artburst-dev/artworks/medium/1/bubblegun.jpg").first | |
| hist = image.quantize(8).color_histogram | |
| pixels_array = [] | |
| pixels = hist.keys.sort_by {|pixel| hist[pixel]} | |
| pixels.each { |pixel| pixels_array << [ pixel.to_color(Magick::AllCompliance,false,8), hist[pixel] ] } | |
| pixels_array.reverse! | |
| pixels_array[0] # ["#34689A", 42766] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment