[Image-SIG] Odd behavior in PIL 1.1.4 equalization

David Kirtley dkirtley at gmail.com
Wed May 4 18:35:25 CEST 2005

Hi all, 

I seem to have found an odd behavior in the equalization.

I created a series of test images with PIL for a demonstration:
  a 300x300 RGB image with three bars of gray with offsets of 20 in
all three channels
 with starting values of 0 to 200 in steps of 50.

I expected the equalization routine to move them to 0, 128, 255 as per
the definition of Histogram Equailzation but to my suprise the
equalization routine decides to instead
set them to 0, 85, 170.

Is this intended functionality? Is this a bug/feature?  :)


------------------------------------- Source used-------------------------

import Image, ImageOps, ImageDraw, ImageFilter

def fill(im,start):
    d = ImageDraw.Draw(im)
    d.rectangle((0,0,99,299), fill=(start+0,start+0,start+0), outline
    d.rectangle((100,0,199,299), fill=(start+20,start+20,start+20),
outline =(start+20,start+20,start+20))
    d.rectangle((200,0,299,299), fill=(start+40,start+40,start+40),
outline =(start+40,start+40,start+40))

    return im

x = Image.new('RGB',(300,300))

original = open('original.csv','w')
equalized = open('equalized.csv','w')
for image_base in [a for a in range(0,200,50)]: 
    a = fill(x, image_base)
    b  = ImageOps.equalize(a) 


More information about the Image-SIG mailing list