简体   繁体   English

无法将 PIL 图像从 Paint.NET 转换为 numpy 数组

[英]Cannot convert PIL image from Paint.NET to numpy array

I am getting a ValueError in numpy when performing operations on images.对图像执行操作时,我在 numpy 中收到ValueError The problem seems to be that the images edited by Paint.NET are missing the RGB dimension when opened using PIL and converted to a numpy array.问题似乎是 Paint.NET 编辑的图像在使用 PIL 打开并转换为 numpy 数组时缺少 RGB 维度。

If PIL is giving you a 861x1091 image when you are expecting an 861x1091x3 image, that is almost certainly because it is a palette image - see here for explanation.如果 PIL 在您期望 861x1091x3 图像时为您提供 861x1091 图像,那几乎可以肯定,因为它是调色板图像 - 请参阅此处的解释。

The simplest thing to do, if you want a 3-channel RGB image rather than a single channel palette image is to convert it to RGB when you open it:最简单的做法是,如果您想要 3 通道 RGB 图像而不是单通道调色板图像,则在打开它时将其转换为 RGB:

im = Image.open(path).convert('RGB')

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

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