img_to_graph#
- sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=None)[源]#
像素到像素梯度连接的图。
边用梯度值加权。
在用户指南中阅读更多信息。
- 参数:
- imgarray-like of shape (height, width) or (height, width, channel)
2D 或 3D 图像。
- maskndarray of shape (height, width) or (height, width, channel), dtype=bool, default=None
图像的可选掩码,仅考虑部分像素。
- return_asnp.ndarray or a sparse matrix class, default=sparse.coo_matrix
用于构建返回的邻接矩阵的类。
- dtypedtype, default=None
返回稀疏矩阵的数据类型。默认为 img 的数据类型。
- 返回:
- graphndarray or a sparse matrix class
计算出的邻接矩阵。
示例
>>> 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]])