0

My objective is to get an ROI that is outlined in the black in image The ideal result.

After using the below Convex Hull Graham code, we are able to get an ROI as shows in image Result of the convex hull graham (overlay in white). Convex Hull Graham is returning only the outter boundary points however, we need to our ROI to consider some intermediary points to give us a crisp shape.

def convex_hull_graham(points):

    TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)

    def cmp(a, b):
        # return (a > b) - (a < b)
        return np.add((a<b), (a>b), dtype=np.float32)

    def turn(p, q, r):
        return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0)
    def _keep_left(hull, r):
        while len(hull) > 1 and turn(hull[-2], hull[-1], r) != TURN_LEFT:
            hull.pop()
        if not len(hull) or hull[-1] != r:
            hull.append(r)
        return hull
    points = list(points)
    points = [list(point) for point in points]

    points = sorted(points)
    l = reduce(_keep_left, points, [])
    u = reduce(_keep_left, reversed(points), [])

    return l.extend(u[i] for i in range(1, len(u) -1)) or l

We have tried several methods including Shapely, Nearest neighbors, KDTree but nothing has worked. Attached are the points in the image. Result of the convex hull graham

The ideal result

This is the link for the points (.npy file) https://drive.google.com/file/d/1CWWOWVgELPXBAG25barpbtWyvBV8WHGG/view?usp=sharing

0 Answers0