python IndexError: недопустимый индекс для скалярной переменной в jupyter - PullRequest
0 голосов
/ 18 июня 2020

Я пытаюсь сделать go через файлы изображений в python. Я продолжаю получать indexError в eachPix [: 3] в пороге функции.

Код предназначен для загрузки данных в формате PNG и загрузки данных изображения.

#folerLoader is a function returning list of files and target. 
pathlist is a list of paths of pictures

dfin = loadImageData(pathlist,target)

#loads image data
def loadImageData(pathList, target):
    finalList = []
    for path in pathList:
        im = Image.open(path, 'r')
        resizedIm = im.resize([28,28])
        image = np.asarray(resizedIm)
        imageThreshold = threshold(image)
        imageRow = imageThreshold.flatten()
        finalList.append(imageRow)
    df = pd.DataFrame(finalList)
    df['class'] = target
    return df

def threshold(imageArray):
    balanceAr = []
    for eachRow in imageArray:
        for eachPix in eachRow:
            avgNum = mean(eachPix[:3]) # where I get error
            balanceAr.append(avgNum)
    balance = mean(balanceAr)

    newMat = []
    for eachRow in imageArray:
        newRow = []
        for eachPix in eachRow:
            if mean(eachPix[:1]) > balance:
                newRow.append(255)

            else:
                newRow.append(0)
        newMat.append(newRow)

    return np.array(newMat)

помогите пожалуйста как решить проблему.

Вышла ошибка, как показано ниже

IndexError                                Traceback (most recent call last)
<ipython-input-91-c6a21e1399e7> in <module>
----> 1 dfin = loadImageData(pathlist,target)

<ipython-input-76-8dd1c50d3083> in loadImageData(pathList, target)
      5         resizedIm = im.resize([28,28])
      6         image = np.asarray(resizedIm)
----> 7         imageThreshold = threshold(image)
      8         imageRow = imageThreshold.flatten()
      9         finalList.append(imageRow)

<ipython-input-90-876634931686> in threshold(imageArray)
      4         for eachPix in eachRow:
      5             x=3
----> 6             avgNum = mean(eachPix[:x])
      7             balanceAr.append(avgNum)
      8     balance = mean(balanceAr)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...