在Python中将图像颜色空间转换为RGB

3

我正在处理图像处理脚本(使用PIL库的Python),需要将任何图像的颜色空间转换为RGB。我尝试了这个技巧,但它只适用于RGBa颜色空间中的png图像:

image = Image.open(imageFile)
image.load()

# replace alpha channel with white color
self.im = Image.new('RGB', image.size, (255, 255, 255))
self.im.paste(image, mask=image.split()[3])

如何使这段代码适用于任何色彩空间的所有图像?
谢谢。
2个回答

2
找到解决方案:
image = Image.open(imageFile)
image.load()

# replace alpha channel with white color
self.im = Image.new('RGB', image.size, (255, 255, 255))
self.im.paste(image, None)

self.im变量中将存储一个带有白色(255, 255, 255) alpha通道的RGB色彩空间图像。


0

你是否知道 skimage xyz2rgb( lab2xyz( lab )) 对于超出色域的lab是否合理? - denis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接