根据我对RGB888 to RGB565的问题,我想做RGB565到RGB888,这是我的测试代码,但是我在转换到RGB888字节数组时遇到了困难
import numpy as np
np.random.seed(42)
im = np.random.randint(0,256,(1,4,2), dtype=np.uint8)
# >>> im.nbytes
# 8
# >>> im
# array([[[102, 220],
# [225, 95],
# [179, 61],
# [234, 203]]], dtype=uint8)
# Make components of RGB888
R8 = (im[...,0] & 0xF8).astype(np.uint32) << 8
G8 = (im[...,0] & 0x07).astype(np.uint32) << 5 | (im[...,1] & 0xE0).astype(np.uint32)
B8 = (im[...,1] & 0x1F).astype(np.uint32)
RGB888 = R8 | G8 | B8
# >>> RGB888.nbytes
# 16 <= here I think it should be 12 (4x3 bytes)
# >>> RGB888.reshape(1, 4, 3)
# Traceback (most recent call last):
# File "<input>", line 1, in <module>
# ValueError: cannot reshape array of size 4 into shape (1,4,3)
当我使用astype(np.uint16)时,一些值变为0,因为它需要更大的数据类型来存储,这就是我在上述代码中使用unit32的原因
我知道unit32将使上述代码的RGB888大小为16,所以我想问一下,是否有其他正确的方式将RGB565传输到RGB888
类似这样的内容可以将您从RGB565
uint16
转换为三个uint8通道阵列,然后您可以将它们dstack
转换为单个三维RGB图像:编辑:要将uint8s的W x H x 2数组转换为uint16s的W x H数组
您可能需要根据源阵列的端向性交换b1和b2
相关问题 更多 >
编程相关推荐