简体   繁体   English

Python Pillow:如何从 1 通道图像生成 3 通道图像?

[英]Python Pillow: how to produce 3-channel image from 1-channel image?

A Python package that I'm trying to use only works with 3-channel images.我尝试使用的 Python 包仅适用于 3 通道图像。 If I have a grayscale PNG image, Pillow's Image.open() naturally reads it as a single-layer image.如果我有灰度 PNG 图像,Pillow 的Image.open()自然会将其读取为单层图像。 How can I use Pillow to transform the 1-channel image into a 3-channel RGB image?如何使用 Pillow 将 1 通道图像转换为 3 通道 RGB 图像?

The simplest method to convert a single-channel greyscale image into a 3-channel RGB image with PIL is probably like this:用PIL将单通道灰度图像转换成3通道RGB图像最简单的方法大概是这样的:

RGB = Image.open('image.png').convert('RGB')

Further discussion and explanation is available here .此处提供进一步的讨论和解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM