Dominant colors with Image package in python
<p>I have a transparent image and I am trying to extract major colors out of it using <code>Image</code> module's <code>getcolor()</code> method</p>

<pre><code>y = Image.open('img.png')
y.getcolors()
[Out]: [(21841, 0),
(13328, 1),
 (8171, 2),
 (2673, 3),
 (1337, 4),
 (1010, 5),
 (892, 6),
 (519, 7),
 (379, 8),
 (234, 9)]
</code></pre>

<p>How do I get actual color values (or names) corresponding to these indexes?</p>

<p><a href="http://i.stack.imgur.com/KctAV.png" rel="nofollow"><img src="http://i.stack.imgur.com/KctAV.png" alt="enter image description here"></a></p>

<p>I am not sure whether the following code snippet is what you are finding. Convert the <code>Image</code> object to RGBA object and use <code>getcolors()</code> as follows.</p>

<pre><code>from PIL import Image

im = Image.open('img.png')
rgba_im = im.convert('RGBA')
print ( rgba_im.getcolors() )

"""
&lt;Output&gt;
[(2673, (218, 215, 209, 255)), (379, (195, 29, 54, 255)), (21841, (208, 208, 209, 0)), (234, (206, 198, 185, 255)), (519, (201, 178, 176, 255)), (1337, (193, 188, 186, 0)), (8171, (182, 176, 174, 0)), (892, (178, 170, 165, 255)), (13328, (168, 26, 41, 255)), (1010, (107, 18, 19, 255))]
"""
</code></pre>

python image pillow