[Image-SIG] Fixes for PIL enhancers

Dinu Gherman gherman@darwin.in-berlin.de
Tue, 7 Jan 2003 16:55:23 +0100


[Sent this before erroneously to Robb and the Pythonmac list... :-/]

Robb Shecter:

> Any suggestions (or more Enhancer implementations!) are appreciated.

Well, I was experimenting with automated enhancers for photographs
and played a bit with the effects of shifting an image's histogram
by some constant offset. (The code below works, but I'm not sure if
this is fully PIL-mantra-compliant?! ;-)

The existing Brightness enhancer is different since it multiplies
pixel values by a factor and the histogram changes its width slight-
ly.

I reckon that it is probably hopeless to try one's hands on fully
automated brightness/contrast enhancement of photographs without
some AI component... But maybe I should try some non-linear ver-
sions, too, before saaying that...

   class Shift(ImageEnhance._Enhance):
     "An enhancer that shifts the histogram of an image by some offset."

     def __init__(self, im):
       self.im =3D im

     def enhance(self, offset):
       return self.im.point(lambda i: i+offset)

Regards,

Dinu

--
Dinu C. Gherman
......................................................................
"La perfection est atteinte, non pas lorsqu'il n'y a plus rien
=E0 ajouter, mais lorsqu'il n'y a plus rien =E0 retirer."
(Antoine de Saint-Exup=E9ry)