def point_inside_polygon(polygon, p, thresh_val=0):
    """
    Returns true if the point p lies inside the polygon (ndarray)
    Checks if point lies in a thresholded area

    :param polygon: ndarray that represents the thresholded image contour that we want to circle pack
    :param p: ndarray 1x2 representing a point in Euclidean N^2 space.
    :param thresh_val: The threshold value that we want to represent inclusion. i.e. if point (x, y)
           in the polygon is <= thresh_val then the point is in the polygon
    :return: True if point p in inside the polygon, False otherwise
    """
    p_x = p[1]
    p_y = p[0]
    if 0 <= p_x < polygon.shape[1] and 0 <= p_y < polygon.shape[0]:
        if polygon[p_y, p_x] <= thresh_val:
            return True
    return False