sklearn.feature_extraction.img_to_graph?

sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse.coo.coo_matrix'>, dtype=None)

[源碼]

圖的像素到像素的梯度連接

邊緣用梯度值加權。

用戶指南中閱讀更多內容。

參數 說明
img ndarray of shape (height, width) or (height, width, channel)
2D或3D圖像。
mask ndarray of shape (height, width) or (height, width, channel), dtype=bool, default=None
可選的圖像遮罩,只考慮部分像素。
return_as np.ndarray or a sparse matrix class, default=sparse.coo_matrix
用來構建返回鄰接矩陣的類。
dtype dtype, default=None
返回稀疏矩陣的數據。默認情況下,它是img的dtype

注意

對于scikit-learn版本0.14.1和之前版本,return_as=np。ndarray是通過返回稠密np來處理的。矩陣實例。展望未來,np。ndarray返回一個np。ndarray,如預期。

為了兼容性,依賴于此方法的用戶代碼應該將其調用封裝在np中。避免類型問題。