python - 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 缓冲区源数组是只读的
有谁知道这意味着什么,或者代码中可能存在什么问题?
解决方案
要修复错误,您只需将 PIL 图像转换为 NumPy 数组,如下所示:
test_glcm = greycomatrix(np.array(img), [1], [np.pi/2], 256, symmetric=True, normed=True)
推荐阅读
- angular - Angular 2中的过滤器参数
- javascript - 寻求帮助为JS编写函数以完成任务
- system-verilog - 有没有办法在 ovm_agent 上运行 uvm_sequences?
- javascript - 如何实现异步循环(JS)
- ruby-on-rails - 在关联情况下覆盖铁轨中的铲子方法
- soap - 在 SoapUI 中保存响应中的附件
- powershell - 使用 PowerShell 从一个大的制表符分隔的文本文件中提取数据,对其进行屏蔽,然后将屏蔽的数据合并回原始文件
- c# - DocuSign.eSign.Api.EnvelopesApi 上的 INVALID_REQUEST_PARAMETER
- php - 返回字符串但不回显到屏幕
- java - 检查 json 数组是否有任何项目