猫史档案馆


【Python作品分享】38-透明通道【求助帖】

用户:·缓城··缓城·查看:0 回复:0 评论:0 创建时间:2021-04-11T10:12:11


【作品展示】

center_image

 

【作品介绍】

因为好久没有打代码了,所以希望大家能帮我逐条解释+翻译,我会很感谢大家的,谢谢谢谢

 

【作品源代码】

from PIL import Image,ImageOps
import matplotlib.pyplot as plt

img = Image.open('bcm.jpg').convert("RGBA")
width, height = img.size
horse = Image.open('horse.png').convert('L').resize(img.size)

img.putalpha(horse) # 传入一个灰度值的图片

#level = 10
_, axes = plt.subplots(1, 4, figsize=(30,30))

# for i in range(level):
#     alpha = int(255/level*l)
#     img.putalpha(alpha)
#     axes[i].imshow(img)
#     axes[i].set_title('alpha={}'.format(alpha))

plt.rcParams['image.cmap'] = 'gray'
axes[0].imshow(img)
axes[1].imshow(horse) # 显示马原来的图片

horse = ImageOps.invert(horse)
axes[2].imshow(img) # 显示马反色之后的图片

img.putalpha(horse)
axes[3].imshow(img)

# plt.imshow
plt.show()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页