我有以下代码:
import cv2
import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage
from sklearn.feature_extraction import image
from sklearn.cluster import spectral_clustering
image = cv2.imread("/home/facu/holo.tif",0)
image = image
spectrum = np.fft.fftshift(np.fft.fft2(image))
intensity = 10*np.log(np.abs(spectrum))
mask = intensity.astype(bool)
img = intensity.astype(float)
graph = image.img_to_graph(img, mask=mask)
graph.data = np.exp(-graph.data/graph.data.std())
labels = spectral_clustering(graph, k=2, mode = 'arpack')
label_img = -np.ones(mask.shape)
label_im[mask] = labels
所以我试图使用“光谱聚类”函数,但我得到了一个错误:
AttributeError: 'numpy.ndarray' object has no attribute 'img_to_graph'
如何将“强度”numpy数组转换为正确的img_to_graph属性?在
您正在用
image = cv2.imread("/home/facu/holo.tif",0)
覆盖导入的image = sklearn.feature_extraction.image
,因此函数img_to_graph
将不再可访问。在解决方案是将其中一个重命名,例如
并相应地调整其余部分。在
相关问题 更多 >
编程相关推荐