PIL 旋转图像颜色(BGR -> RGB) [英] PIL rotate image colors (BGR -> RGB)

查看:52
本文介绍了PIL 旋转图像颜色(BGR -> RGB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片,颜色是 BGR.如何转换我的 PIL 图像以有效地交换每个像素的 B 和 R 元素?

I have an image where the colors are BGR. How can I transform my PIL image to swap the B and R elements of each pixel in an efficient manner?

推荐答案

假设没有 alpha 波段,是不是就这么简单?

Assuming no alpha band, isn't it as simple as this?

b, g, r = im.split()
im = Image.merge("RGB", (r, g, b))

嗯...似乎 PIL 在这方面有一些错误... im.split() 似乎不适用于最新版本的 PIL (1.1.7).它可能 (?) 仍然适用于 1.1.6,不过...

Hmm... It seems PIL has a few bugs in this regard... im.split() doesn't seem to work with recent versions of PIL (1.1.7). It may (?) still work with 1.1.6, though...

这篇关于PIL 旋转图像颜色(BGR -> RGB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆