def gap_right(hist, x, th, W, K=10):
    """
    Checks if this x-coordinate marks the end of a word/block.
    :param hist: distribution of pixels.
    :param x: x-coordinate.
    :param th: threshold value.
    :param K: number of columns of empty pixels to consider as new word/block.
    :return: whether this x-coordinate marks the end of a word/block.
    """
    gap = hist[x-1] > th
    for i in range(K):
        if x + i > W:
            break
        gap = gap and (x+i >= len(hist) or hist[x+i] <= th)
    return gap