今天晚上,做Python时,遇到了以下bug:
我的代码
from PIL import Image, ImageMath
img = Image.open('photo.jpg').convert('RGB')
image = img.split()
R, G, B = 2, 0, 0
width, height = img.size
img_rs = img.crop((0, 0, width/4, height))
img_gs = img.crop((width/4, 0, width/2, height))
img_bs = img.crop((width/2, 0, width/4*3, height))
img_ns = img.crop((width/4*3, 0, width, height))
mode = '255-(255-a)*(255-b)/255'
out_r = ImageMath.eval(mode, a=image[R], b=image[R]).convert('L')
out_g = ImageMath.eval(mode, a=image[G], b=image[G]).convert('L')
out_b = ImageMath.eval(mode, a=image[B], b=image[B]).convert('L')
Image.merge('RGB', (out_r,out_g,out_b))
img.show()
题目
运行效果
问题
问题是,我的代码已经很明确了(其实少了几个),为什么显示不出来?
(图片来自编程猫PythonP2课第47课拓展创作)
欢迎在评论区指点。