img_to_graph (图像转图)#
- sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=None)[source]#
- 像素到像素梯度连接图。 - 边权重为梯度值。 - 更多信息请参考 用户指南。 - 参数:
- img形状为 (height, width) 或 (height, width, channel) 的类数组
- 二维或三维图像。 
- mask形状为 (height, width) 或 (height, width, channel),dtype=bool,默认值=None 的 ndarray
- 图像的可选掩码,仅考虑部分像素。 
- return_asnp.ndarray 或稀疏矩阵类,默认为 sparse.coo_matrix
- 用于构建返回的邻接矩阵的类。 
- dtypedtype,默认值=None
- 返回的稀疏矩阵的数据类型。默认为 img 的数据类型。 
 
- 返回值:
- graphndarray 或稀疏矩阵类
- 计算出的邻接矩阵。 
 
 - 示例 - >>> import numpy as np >>> from sklearn.feature_extraction.image import img_to_graph >>> img = np.array([[0, 0], [0, 1]]) >>> img_to_graph(img, return_as=np.ndarray) array([[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1], [0, 1, 1, 1]]) 
