首页 > 解决方案 > ValueError 缓冲区源数组是只读的

问题描述

我正在使用此代码为某个图像提取 GLCM 特征,但它给了我一个值错误

代码:

from PIL import Image
from skimage.feature import greycomatrix, greycoprops
fname = 'trial.jpg'
img = Image.open(fname).convert("L")
img = img.resize((224, 224))
test_glcm = greycomatrix(img, [1], [np.pi/2], 256, symmetric=True, normed=True)

错误:

ValueError 缓冲区源数组是只读的

有谁知道这意味着什么,或者代码中可能存在什么问题?

标签: pythonscikit-imageglcm

解决方案


要修复错误,您只需将 PIL 图像转换为 NumPy 数组,如下所示:

test_glcm = greycomatrix(np.array(img), [1], [np.pi/2], 256, symmetric=True, normed=True)

推荐阅读