[Image-SIG] PIL module, auto-levels adjust
Kevin Cazabon
KCAZA@cymbolic.com
Tue, 16 Feb 1999 12:08:46 -0800
This is a MIME message. If you are reading this text, you may want to
consider changing to a mail reader or gateway that understands how to
properly handle MIME multipart messages.
--=_0A5DF84D.137211E7
Content-Type: text/plain
Content-Disposition: inline
I've written a handy little module for automatically fine-tuning image files. It will work with RGB and CMYK files, and does the following:
-checks the histogram, determines the actual brightness range used in the image for each channel
-scales the data to fill the full 0-255 range either by scaling each channel individually, or by scaling them equally (to the lowest common denomonator)
Being a certified Adobe Photoshop 4.0 instructor (by Adobe), I find the BEST way to color/density correct an image is to first set the black/white point for each of the channels individually, so that you use the entire available dynamic range. This is basically what the module does.
The usage is as follows:
###################################
import Image
import levels
file = Image.open('filename')
file = levels.levels(file, scale_same, clip)
###################################
scale_same: 0 = scale each channel individually, 1 = scale all channels the same
clip = (integer) = if there's less than this number of pixels at the minimum/maximum brightness level found, don't use them to calculate the levels adjustment (i.e. they get clipped off the image to pure black/white) default is 0. This is useful if you have a few 'dark' or 'bright' pixels that actually are not relevant detail and are causing the scaling to not properly fill up the histogram.
###################################
It's not the most glamourous code, but it works very well. It's great for batch-processing scanned images to 'tweak' the dynamic range, and do a pretty decent job at color correction too. (most of the time, optimizing the RGB/CMYK channels to each fill the entire dynamic range does a good color correction too).
If you find it useful... please let me know!
Kevin Cazabon, B.A.A.
kcazabon@rogers.wave.ca
kcaza@cymbolic.com
!
--=_0A5DF84D.137211E7
Content-Type: application/zip
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="levels.py.zip"
Content-Description: PKZIP (compressed) files
UEsDBBQAAAAIAMtgUCZsEXXuzQIAAA0KAAAJACQAbGV2ZWxzLnB5CgAgAAAAAAABABgAALOv0udZ
vgEAQMpZglm+AcCK9dHnWb4BrVVdb9o8FL5H4j8cqRckW5oCGl2L1qpaL6ZX1XaxuymKkBNM6sWJ
kRPY3v36+SMfthNYqw0JCPZznnOecx6bC0Db74eqBoqPmFZQM9gR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