list conversion question
ptmcg at austin.rr._bogus_.com
Sat Sep 4 05:37:35 CEST 2004
"Kent Tenney" <kent at springfed.com> wrote in message
news:mailman.2860.1094267481.5135.python-list at python.org...
> I am using PIL, and would like to
> make a list of the pixel values
> in an image, sorted by quantity of
> pixels with that value.
> im.histogram() returns a list which
> is a pixel count for each brightness value.
> So, I want to sort the histogram, and have
> the resulting list contain
> the indexes instead of the counts.
> This seems like it'd be a fairly common
> task, but I don't know what to call
> it to look for guidance.
> Any help is appreciated.
Assuming im.histogram() returns a list like [ 0, 1, 0, 5, 43, etc. ] how
hist = [ 0, 1, 0, 5, 43 ]
values = [ i for i in enumerate(hist)]
values.sort(lambda a,b: cmp(b,a))
indexes = [ a for a,b in values ]
More information about the Python-list