我想在图像的所有侧面添加零。我尝试:
from PIL import Image
im = Image.open("/content/drive/My Drive/image31.png")
def pad(im,layers):
return [[0]*(len(im[0])+2*layers)]*layers + \
[[0]*layers+r+[0]*layers for r in im] + \
[[0]*(len(im[0])+2*layers)]*layers
pad(im,1)
错误是:TypeError: 'PngImageFile' object does not support indexing