[Image-SIG] ImageOps.equalize division by zero

Douglas Bagnall douglas at paradise.net.nz
Mon Mar 8 23:15:06 EST 2004


hello,

For images with fewer than 255 pixels, ImageOps.equalize raises a 
ZeroDivisionError.

     h = image.histogram()
     #...
     for b in range(0, len(h), 256):
         step = reduce(operator.add, h[b:b+256]) / 255
         n = 0
         for i in range(256):
             lut.append(n / step)  # error shows up here
             n = n + h[i+b]


AFAICT, using a float for step works best, but a trusty old "or 1" is 
tolerable for all but the tiniest images.

As a matter of curiousity, is  reduce(operator.add, h[b:b+256]) (for b,h 
above) ever different from image.size[0] * image.size[1] ?



douglas bagnall


-------------- next part --------------
A non-text attachment was scrubbed...
Name: float.patch
Type: text/x-patch
Size: 213 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20040309/27fae83f/float.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: int.patch
Type: text/x-patch
Size: 129 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20040309/27fae83f/int.bin


More information about the Image-SIG mailing list