def get_block_signature(img, left, top, right, bottom):
    """
    Get an image block's signature.

    The signature is a list of the running indices of the black pixels
    in the block.

    ``left``, ``top``, ``right`` and ``bottom`` specify the borders of
    the block. ``left`` and ``top`` are inclusive, ``right`` and
    ``bottom`` are exclusive.
    """
    columns = img.size[0]
    data = img.getdata()
    sig = []
    width = right - left
    for y in range(top, bottom):
        for x in range(left, right):
            index = x + y * columns
            if not data[index]:
                sig.append((x - left) + width * (y - top))
    return tuple(sig)