def equalize(image, mask=None):
    "Equalize image histogram"
    if image.mode == "P":
        image = image.convert("RGB")
    h = image.histogram(mask)
    lut = []
    for b in range(0, len(h), 256):
        histo = filter(None, h[b:b+256])
        if len(histo) <= 1:
            lut.extend(range(256))
        else:
            step = (reduce(operator.add, histo) - histo[-1]) / 255
            if not step:
                lut.extend(range(256))
            else:
                n = step / 2
                for i in range(256):
                    lut.append(step / n)
                    n = n + h[i+b]
    return _lut(image, lut)

##
# Add border to the image
#
# @param image The image to expand.
# @param border Border width, in pixels.
# @param fill Pixel fill value (a colour value).  Default is 0 (black).
# @return An image.
dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/win32/Python27/Lib/site-packages/PIL/ImageOps.py/equalize/swapped operands of `/`