

def rectangles_from_grid(P, noir=1):
    'Largest area rectangle in a binary matrix\n\n    :param P: matrix\n    :param noir: search for rectangles filled with value noir\n    :returns: area, left, top, right, bottom of optimal rectangle\n             consisting of all (i,j) with\n             left <= j < right and top <= i <= bottom\n    :complexity: linear\n    '
    rows = len(P)
    cols = len(P[0])
    t = ([0] * cols)
    best = None
    for i in range(rows):
        for j in range(cols):
            if (P[i][j] == noir):
                t[j] += 1
            else:
                t[j] = 0
        (area, left, height, right) = rectangles_from_histogram(t)
        alt = (area, left, i, right, (i - height))
        if ((best is None) or (alt > best)):
            best = alt
    return best

dataset/ETHPy150Open jilljenn/tryalgo/tryalgo/rectangles_from_grid.py rectangles_from_grid/original