[Image-SIG] roop found an interesting flaw in PIL's ImageEnhance.py
Fredrik Lundh
fredrik at pythonware.com
Tue Jun 16 20:54:49 CEST 2009
On Mon, Jun 15, 2009 at 11:06 PM, Scott David
Daniels<Scott.Daniels at acm.org> wrote:
> roop wrote:
>> I was browsing ImageEnhace.py, and found something that I thought was
>> odd in class Contrast:
>>
>> class Contrast(_Enhance):
>> "Adjust image contrast"
>> def __init__(self, image):
>> self.image = image
>> mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/
>> 256.0
>> self.degenerate = Image.new("L", image.size, mean).convert
>> (image.mode)
>>
>> Isn't reduce(lambda a,b: a+b, image.convert("L").histogram()) the same
>> as (image.size[0] * image.size[1]) - just count the number of pixels
>> in the image? (Afaik, the histogram is a list of 256 elements where
>> the ith element gives the number of pixels with i as the pixel value
>> (0 <= i < 256)). Is this actually fishy or have I got it all muddled
>> up?
>>
>> Thanks,
>> roop
>
> Good catch [I'll send a copy to the imaging sig]. If you replace class
> Contrast like this:
And the award for finding the oldest bug in PIL goes to... (that code
was last touched in 1996).
I've checked in a last-second fix for 1.1.7 (to be frozen any day soon
now, promise).
Thanks /F
More information about the Image-SIG
mailing list