def DoNotPassBorder(grid, point2d):
    """Ensure point is in image
    Arg: grid <- image
         pinrt2d <- x,y
    Returns: new point
    """
    x = point2d[0]
    y = point2d[1]
    if x < 0:
        x = 0
    elif x > grid.shape[0]:
        x = len(grid)
    if y < 0:
        y = 0
    elif y > grid.shape[1]:
        y = len(grid)
    return x, y
