import math


def bbox_to_integer_coords(t, l, b, r, image_h, image_w):
    """
        t, l, b, r:
            float
            Bbox coordinates in a space where image takes [0; 1] x [0; 1].
        image_h, image_w:
            int

        return: t, l, b, r
            int
            Bbox coordinates in given image's pixel space.
            C-style indices (i.e. `b` and `r` are exclusive).
    """
    t *= image_h
    l *= image_h
    b *= image_h
    r *= image_h

    l, t = map(math.floor, (l, t))
    r, b = map(math.ceil, (r, b))

    # After rounding, make *exactly* square again
    b += (r - l) - (b - t)
    assert b - t == r - l

    # Make `r` and `b` C-style (=exclusive) indices
    r += 1
    b += 1
    return t, l, b, r