python查看图片通道数_python – 如何检查图像的通道顺序?

将图像加载到Python中,如下所示,我如何知道通道的顺序? (例如BGR或RGB)

from PIL import Image

import numpy as np

image_pil = Image.open("Stonehenge.jpg")

image_np = np.array(image_pil)

image_np[0][0]

结果

array([ 52, 123, 155], dtype=uint8)

具体问题

我怎么知道52是对应红色通道,蓝色通道还是不同的通道?或者这个问题在概念层面上没有意义吗?

笔记

在类似于Java而不是Python的问题中,one person claims:

If you are reading in the image file, or you have access to the code

that reads in the file, know it is:

BGR order if you used cv2.imread(),

RGB order if you used mpimg.imread(), (assuming import matplotlib.image as mpimg)

If you don’t know how the file was opened, the accepted answer

BufferedImage is great for Java.

解决方法:

由于您使用PIL并且未指定任何其他模式来加载Image,因此您获得R G B.

您可以通过检查Image实例上的“mode”属性来验证:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值