[Image-SIG] Auto level with PIL?
stefano at pragma2000.com
Wed Sep 7 22:09:34 CEST 2005
Autolevel basically works by analyzing the histogram of the image.
The histogram of an 8-bit image is basically a set of 256 counters
(32767 if working in 16-bit mode) for each channel. Each one counts
how many bits are the in the image for the specified intensity value.
A pixel with color (100, 200, 150) increments by one the 100th red
counter, the 200th green one and the 150th blue one.
After building the histogram, you look at the lowest value that counts
at least one pixel, and the highest. Say that in your image no pixel
has a colour darker than (10, 15, 7) and no one brighter than (250,
247, 200). It means that the range of your image is 7-250.
Last step, you scale the values of each pixels proportionally so that
7 becomes 0, 250 becomes 255 and whatever in between is proportionally
it's a rough explanation... but I hope it helps.
On 9/7/05, Chris Barker <Chris.Barker at noaa.gov> wrote:
> Hi all,
> I need to do something like Photoshop's Auto Level to a bunch of images.
> Honestly, I have only a vague idea of what it does, but I saw that
> someone posted a script to do it here about 6 years ago, but I can't
> seem to get that code from the list archives. It's also possible that
> someone has improved upon it in all those years. Has anyone got any code
> for this?
> A pointer to a good description of what auto level is would be nice too.
> Christopher Barker, Ph.D.
> NOAA/OR&R/HAZMAT (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
> Chris.Barker at noaa.gov
> Image-SIG maillist - Image-SIG at python.org
More information about the Image-SIG