用法:
skimage.graph.route_through_array(array, start, end, fully_connected=True, geometric=True)
如何使用 MCP 和 MCP_Geometric 类的简单示例。
有关 path-finding 算法的说明,请参阅 MCP 和 MCP_Geometric 类文档。
- path:列表
n-d 索引元组列表定义从开始到结束的路径。
- cost:浮点数
路径的成本。如果几何的是假的,路径的成本是值的总和
array
沿着路径。如果几何的为真,进行更精细的计算(参见MCP_Geometric 类的文档)。
参数:
返回:
例子:
>>> import numpy as np >>> from skimage.graph import route_through_array >>> >>> image = np.array([[1, 3], [10, 12]]) >>> image array([[ 1, 3], [10, 12]]) >>> # Forbid diagonal steps >>> route_through_array(image, [0, 0], [1, 1], fully_connected=False) ([(0, 0), (0, 1), (1, 1)], 9.5) >>> # Now allow diagonal steps: the path goes directly from start to end >>> route_through_array(image, [0, 0], [1, 1]) ([(0, 0), (1, 1)], 9.19238815542512) >>> # Cost is the sum of array values along the path (16 = 1 + 3 + 12) >>> route_through_array(image, [0, 0], [1, 1], fully_connected=False, ... geometric=False) ([(0, 0), (0, 1), (1, 1)], 16.0) >>> # Larger array where we display the path that is selected >>> image = np.arange((36)).reshape((6, 6)) >>> image array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35]]) >>> # Find the path with lowest cost >>> indices, weight = route_through_array(image, (0, 0), (5, 5)) >>> indices = np.stack(indices, axis=-1) >>> path = np.zeros_like(image) >>> path[indices[0], indices[1]] = 1 >>> path array([[1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1]])
相关用法
- Python skimage.feature.graycomatrix用法及代码示例
- Python skimage.color.lab2lch用法及代码示例
- Python skimage.draw.random_shapes用法及代码示例
- Python skimage.feature.blob_doh用法及代码示例
- Python skimage.feature.blob_dog用法及代码示例
- Python skimage.filters.unsharp_mask用法及代码示例
- Python skimage.registration.optical_flow_tvl1用法及代码示例
- Python skimage.filters.rank.noise_filter用法及代码示例
- Python skimage.exposure.histogram用法及代码示例
- Python skimage.filters.gaussian用法及代码示例
- Python skimage.feature.graycoprops用法及代码示例
- Python skimage.segmentation.active_contour用法及代码示例
- Python skimage.feature.corner_orientations用法及代码示例
- Python skimage.exposure.adjust_gamma用法及代码示例
- Python skimage.morphology.h_minima用法及代码示例
- Python skimage.filters.threshold_otsu用法及代码示例
- Python skimage.feature.structure_tensor用法及代码示例
- Python skimage.transform.hough_circle_peaks用法及代码示例
- Python skimage.morphology.dilation用法及代码示例
- Python skimage.draw.polygon2mask用法及代码示例
注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.graph.route_through_array。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。