def find_edge_points(cluster_points, grid_shape): """ Identify the edge points of a cluster on a grid. Parameters: cluster_points (list of tuples): List of (x, y) tuples representing points in the cluster. grid_shape (tuple): The shape of the grid (height, width). Returns: list: A list of (x, y) tuples representing the edge points of the cluster. """ grid = np.zeros(grid_shape, dtype=bool) for x, y in cluster_points: grid[y, x] = True # Mark the point as part of the cluster eroded_grid = binary_erosion(grid) # Edge points are original grid points minus eroded points edge_grid = grid & ~eroded_grid edge_points = np.argwhere(edge_grid) return np.array([(x, y) for y, x in edge_points])