Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

Python
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()
Posted
Updated 29-Oct-16 22:21pm
v3

1 solution

It seems that a numpy array is read-only; see python - Change values in a numpy array - Stack Overflow[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900