def is_legal(x, y, img):
    """
    Check if (x, y) is a valid coordinate in img

    Args:
        x (int): x-coordinate
        y (int): y-coordinate
        img (numpy.array): Image
    
    Returns:
        bool -> True if valid, False otherwise
    """
    if 0 <= x < img.shape[1] and 0 <= y < img.shape[0]:
        return True
    else:
        return False