cmax = centerline['col'].max() centerline_image = centerline_image[rmin:rmax, cmin:cmax] centerline_ind = np.array(np.where(centerline_image == 1)).T # plt.imshow(centerline_image) # plt.scatter(i[1], i[0]) # plt.show() image = None ds = None # Get Endpoints endpoint1 = centerline_ind[0] endpoint2 = centerline_ind[-1] costs = np.where(centerline_image, 1, 1000) route, cost = graph.shortest_path( centerline_image, reach=2, output_indexlist=True ) test = pandas.DataFrame(route, columns=['row', 'col']) plt.imshow(centerline_image) plt.scatter(test['col'], test['row']) plt.show()
from skimage import graph, color bh = io.imread('borehole_stringer.png') p, cost = graph.shortest_path(color.rgb2grey(bh), reach=1) plt.imshow(bh, cmap=plt.cm.gray) plt.plot(np.arange(bh.shape[1]), p, 'r-')
from skimage import graph, color bh = io.imread('borehole_stringer.png') p, cost = graph.shortest_path(color.rgb2grey(bh), reach=1) plt.imshow(bh, cmap=plt.cm.gray) plt.plot(np.arange(bh.shape[1]), p, 'r-');
def shortest_path(self, reach=1, axis=-1, output_indexlist=False): '''see skimage.graph.shortest_path''' return graph.shortest_path(self, reach, axis, output_indexlist)