【python图像处理】给图像添加透明度(alpha通道)
【python图像处理】给图像添加透明度(alpha通道) 我们常见的RGB图像通常只有R、G、B三个通道,在图像处理的过程中会遇到往往需要向图像中添加透明度信息,如公司logo的设计,其输出图像文件就需要添加透明度,即需要在RGB三个通道的基础上添加alpha通道信息。这里介绍两种常见的向RGB图像中添加透明度的方法。 1、使用图像合成(blending)的方法 可参考(python图像处理——两幅图像的合成一幅图像(blending two images)) 代码如下: [python] view plain copy #-*-coding:UTF-8-*- fromPILimportImage defaddTransparency(img,factor=0.7): img=img.convert('RGBA') img_blender=Image.new('RGBA',img.size,(0,0,0,0)) img=Image.blend(img_blender,img,factor) returnimg img=Image.open("SMILEY.png") img=addT...

