def pad_box(bounding_box, padding, image_shape):
    """
    Add padding around given bounding box making sure not to exceed boundaries
    of the image. bounding_box is 4-tuple (min_row, min_col, max_row, max_col).
    Returns a new bounding_box as a 4-tuple.
    """
    (min_row, min_col, max_row, max_col) = bounding_box
    min_row = max(min_row - padding, 0)
    min_col = max(min_col - padding, 0)
    max_row = min(max_row + padding, image_shape[0])
    max_col = min(max_col + padding, image_shape[1])
    return (min_row, min_col, max_row, max_col)