xThresh, yThresh = boolean_to_scatter(tVesselnessImage, np.arange(0, 101, 1, dtype=int), np.arange(0, 101, 1, dtype=int)) coordinates = np.column_stack((xThresh, yThresh)) xRange = create_mapping_function((0, 100), (xMin, xMax)) yRange = create_mapping_function((0, 100), (yMin, yMax)) grid = np.arange(0, 101, 1, dtype=int) dbscan = HDBSCAN() clusters = dbscan.fit_predict(coordinates) boundaries = list() for cluster in set(clusters): if cluster == -1: continue clusterX = coordinates[:, 0][clusters == cluster] clusterY = coordinates[:, 1][clusters == cluster] clusterPoints = np.column_stack((clusterX, clusterY)) if len(clusterPoints > 5): try: vertices = find_edge_points(np.vstack((clusterX, clusterY)).T, (100, 100)) xVert = grid[vertices[:, 0]] yVert = grid[vertices[:, 1]] bPoints = np.vstack((xVert, yVert)).T boundaries.append(BoundaryRegion(bPoints, xRange=xRange, yRange=yRange)) except QhullError: print(f"Skipping Cluster {cluster} due to QHull Error (such as geometry degeneracy)") # fig.savefig("WrinkDetectBinCollapse.png")