我做错了什么? [英] What I am doing wrong ?

查看:104
本文介绍了我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中收到此错误

回溯(最近一次调用最后一次):

i am getting this error in my program
Traceback (most recent call last):

File "D:\Python\programs\IMG PRO\im.py", line 30, in <module>
    threshhold(iar)
File "D:\Python\programs\IMG PRO\im.py", line 17, in threshhold
    echpix[0]=255
ValueError: assignment destination is read-only





我尝试过:





What I have tried:

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import time
def threshhold(imagearray):
    newa=imagearray
    bal=list()
    for echrow in imagearray:
        for echpix in echrow:
            avg=sum(echpix[:3])/3
            bal.append(avg)
    s=sum(bal[0:])
    balance=s/len(bal)
    for echrow in newa:
        for echpix in echrow:
            if (sum(echpix[:3])/3)>balance:
                echpix[0]=255
                echpix[1]=255
                echpix[2]=255
                echpix[3]=255
            else:
                echpix[0]=0
                echpix[1]=0
                echpix[2]=0
                echpix[3]=255
    print newa

im=Image.open('../images/numbers/y0.3.png')
iar=np.asarray(im)
threshhold(iar)
fig=plt.figure()
ax1=plt.subplot2grid((8,6),(0,0),rowspan=4,colspan=3)
ax1.imshow(iar)
plt.show()

推荐答案

似乎numpy数组是只读的;请参阅 python - 更改numpy数组中的值 - Stack Overflow [ ^ ]。
It seems that a numpy array is read-only; see python - Change values in a numpy array - Stack Overflow[^].


这篇关于我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆