关于python读取RGB图像的问题

记录一下我在使用python中的scipy.misc中的imread的问题。

 

调用函数为

from scipy.misc import imread

image_path = './testimg.jpg'
img = imread(image_path, mode = 'RGB')

原图是:

之后直接用RGB的方式保存出来的图像其实是:

一开始还以为是我哪里的代码出了一点问题,可是后来发现并非如此,在cv2的__init__.py文件中,从cvtColor函数里面的声明这样写道:

The function converts an input image from one color space to another. In case of a transformation to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.

这也就说明了这个问题,OpenCV里面的默认存储方式虽然写作RGB但是实际上存储是BGR图像,所以在直接当成RGB来进行imwrite的时候当然会出问题。

 

当然,没有什么特别好的解决办法,不过暂时还没有影响到使用。颜色空间的转换只要不单独做处理的话也是不会有什么问题的。实在不行,有一个办法:

img = img[:, :, ::-1]

不过感觉这种操作放到网络里面会特别慢,不到万不得已我还是尽量不去使用它。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值