Я новичок в Python и этот код, который я собирался отображать только что получил от http://pythonprogramming.net/automated-image-thresholding-python/?completed=/thresholding-python-function/, я получаю эту ошибку:IndexError? что это и как это исправить
Warning (from warnings module):
File "C:/Users/User/Desktop/tolong aku/thresholding logic.py", line 15
avgNum = reduce(lambda x, y: x + y, eachPix[:3])/len(eachPix[:3])
RuntimeWarning: overflow encountered in ubyte_scalars
Warning (from warnings module):
File "C:/Users/User/Desktop/tolong aku/thresholding logic.py", line 21
if reduce(lambda x, y: x + y, eachPix[:3])/len(eachPix[:3]) > balance:
RuntimeWarning: overflow encountered in ubyte_scalars
Traceback (most recent call last):
File "C:/Users/User/Desktop/tolong aku/thresholding logic.py", line 41, in <module>
iar = threshold(iar)
File "C:/Users/User/Desktop/tolong aku/thresholding logic.py", line 25, in threshold
eachPix[3] = 0
IndexError: index 3 is out of bounds for axis 0 with size 3
, как я могу это исправить и что такое не так ли?
это мой питон 2.7 кода на окнах ..
# if you are on 32 bit OS:
#import Image
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import time
def threshold (imageArray):
balanceAr = []
newAr = imageArray
for eachRow in imageArray:
for eachPix in eachRow:
avgNum = reduce(lambda x, y: x + y, eachPix[:3])/len(eachPix[:3])
balanceAr.append(avgNum)
balance = reduce(lambda x, y: x + y, balanceAr)/len(balanceAr)
for eachRow in newAr:
for eachPix in eachRow:
if reduce(lambda x, y: x + y, eachPix[:3])/len(eachPix[:3]) > balance:
eachPix[0] = 255
eachPix[1] = 255
eachPix[2] = 255
eachPix[3] = 0
else:
eachPix[0] = 0
eachPix[1] = 0
eachPix[2] = 0
eachPix[3] = 255
return newAr
i = Image.open ('C:/Users/User/Desktop/tolong aku/50.0.png')
iar = np.array(i)
i2 = Image.open ('C:/Users/User/Desktop/tolong aku/50.1.png')
iar2 = np.array(i2)
iar = threshold(iar)
iar2 = threshold(iar2)
fig = plt.figure()
ax1 = plt.subplot2grid((8,6), (0,0), rowspan=4, colspan=3)
ax2 = plt.subplot2grid((8,6), (4,0), rowspan=4, colspan=3)
ax1.imshow(iar)
ax2.imshow(iar2)
plt.show()
я хочу, чтобы повернуть изображение на серый пиксел, а затем собирать результаты массива, чтобы сделать set..tq данных.
Я на самом деле просто новичок в python.i уже прочитал базовый python, такой как http://www.python-course.eu/ course.php, http://www.tutorialspoint.com/python/index.htm, https://samarthbhargav.wordpress.com/2014/05/05/image-processing-with-python-rgb-to-grayscale- преобразование/.so, я очень сожалею о том, что задал такой типичный вопрос, как this.very оценить все помогает. – Amr