Python 从Y Cb Cr numpy数组重新创建图像

Python 从Y Cb Cr numpy数组重新创建图像,python,python-imaging-library,numpy-ndarray,Python,Python Imaging Library,Numpy Ndarray,我有3个带有Y、Cb和Cr的numpy数组。我能够单独显示它们,现在我想合并它们并显示结果图像。 我试过这个: Y, Cb, Cr = somefunction() //returns 3 numpy.ndarrays print(Y.shape) //(160, 160) print(Y.dtype) //float64 print(Cb.shape) //(160,160) print(Cb.dtype) //float32 print(Cr.shape) //(160,160) pr

我有3个带有Y、Cb和Cr的numpy数组。我能够单独显示它们,现在我想合并它们并显示结果图像。 我试过这个:

Y, Cb, Cr = somefunction() //returns 3 numpy.ndarrays

print(Y.shape)  //(160, 160)
print(Y.dtype)  //float64
print(Cb.shape) //(160,160)
print(Cb.dtype) //float32
print(Cr.shape) //(160,160)
print(Cr.dtype) // float32

img_Y = im.fromarray(Y, mode=None)
img_Cb = im.fromarray(Cb, mode=None)
img_Cr = im.fromarray(Cr, mode=None)

im.merge('YCbCr', (img_Y, img_Cb, img_Cr))
但我得到了这个错误:

    im.merge('YCbCr', (img_Y, img_Cb, img_Cr))
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2957, in merge
    raise ValueError("mode mismatch")
ValueError: mode mismatch

不能将
float64
Y通道与
float32
Cb/Cr通道合并,并且PIL不支持任何(模式)与多个32位浮点通道合并


因此,您需要将您的值缩放到0..255的范围,并按照上面的链接转换为
uint8
,以便转到
YCbCr
颜色空间。

请显示
Y.shape
,同样
Cb.shape
Cr.shape
。还有他们的
dtype
。谢谢。我刚刚加了它,谢谢。这能回答你的问题吗?不幸的是,不,我想用3个组件Y Cb Cr直接显示它们,这在不转换为RGB的情况下是可能的吗?太棒了!请考虑将它作为答案,点击投票计数旁边的记号,并可能投票。祝你的项目好运。完成!对不起,我还不能投票,我没有足够的声誉