大家好,并提前致谢, 我在论坛上写信给你,请求你的帮助。 我在使用PIL反转图像的程序上遇到问题。 Voici le code complet:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PIL import Image
import random as r
from math import *
def ouvrir(nomimage):
img=Image.open(nomimage)
return img
def affiche(img):
img.show()
def imc2img(imc,n):
img=Image.new("F",imc.size)
pixc=imc.load()
pixg=img.load()
width = imc.size[0]
height=imc.size[1]
for j in range(height):
for i in range(width):
pixg[i,j]=pixc[i,j][n]
return img
def imc2r(ims):
imr=imc2img(ims,1)
return imr
def inverse_image(ims):
img=Image.new("L",ims.size)
pixc=ims.load()
pixg=img.load()
width=ims.size[0]
height=ims.size[1]
for j in range(height):
for i in range(width):
imi=pixg[i,j]=pixc[(255-i),(255-j)]
return imi
找到问题并尝试解决此问题?
def inverse_image(ims):
img=Image.new("L",ims.size)
pixc=ims.load()
pixg=img.load()
width=ims.size[0]
height=ims.size[1]
for j in range(height):
for i in range(width):
imi=pixg[i,j]=255-pixc[i,j]
return imi
错误代码是:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
imi=inverse_image(ims)
File "C:\Users\Geoffray\Desktop\TP_note\code.py", line 43, in inverse_image
imi=pixg[i,j]=255-pixc[i,j]
TypeError: unsupported operand type(s) for -: 'int' and 'tuple'
谢谢你! 我希望我的解释足够清楚。