img_to_graph#
- sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=None)#
图的像素到像素梯度连接。
边用梯度值加权。
更多信息请参阅 用户指南 。
- Parameters:
- 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。
- Returns:
- graphndarray 或稀疏矩阵类
计算的邻接矩阵。
Examples
>>> 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]])