img_to_graph#
- sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=None)[source]#
像素到像素梯度连接的图。
边的权重是梯度值。
Read more in the User Guide.
- 参数:
- img形状为 (height, width) 或 (height, width, channel) 的类数组对象
2D 或 3D 图像。
- mask形状为 (height, width) 或 (height, width, channel) 的 ndarray,dtype=bool,默认值=None
图像的可选掩码,仅考虑部分像素。
- return_asnp.ndarray 或稀疏矩阵类,默认值=sparse.coo_matrix
用于构建返回的邻接矩阵的类。
- dtypedtype,默认值=None
返回稀疏矩阵的数据类型。默认情况下,它与 img 的 dtype 相同。
- 返回:
- 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]])