我正在尝试提取这样的边缘特征:
img = io.imread('pic.jpg')
H, W, C = img.shape
features = custom_features(img)
assignments = kmeans_fast(features, num_segments)
segments = assignments.reshape((H, W))
# Display segmentation
plt.imshow(segments, cmap='viridis')
plt.axis('off')
plt.show()
自定义功能:
from skimage.filters import prewitt_h,prewitt_v
def custom_features(image):
"""
Args:
img - array of shape (H, W, C)
Returns:
features - array of (H * W, C)
"""
edges_prewitt_horizontal = prewitt_h(image)
return edges_prewitt_horizontal
但是,目前我收到一个错误,因为图像的形状与函数预期的不同prewitt_h
。
ValueError: The parameter `image` must be a 2-dimensional array
如何在函数内部修改它以使返回的形状符合需要?