好的,标题已经很明显了。我有一张图片文件,想要将其分别分离为Y、Cb和Cr。在打开文件后,将其从RGB(这是打开图像文件时的默认模式)转换为YCbCr,然后使用numpy.array()将其转换为数组时,它产生了一个具有4个通道的2D数组,这不是我所期望的,因为根据文档的说明,应该只有3个通道。
导致
这是我在解释器中做的事情:
ImageFile = Image.open('filePath', 'r')
ImageFile = ImageFile.convert('YCbCr')
ImageFileYCbCr = numpy.array(ImageFile)
ImageFileYCbCr
导致
array([[[103, 140, 133, 95],
[140, 133, 91, 141],
[132, 88, 141, 131],
...,
[129, 65, 146, 129],
[ 64, 146, 130, 65],
[146, 129, 64, 147]],
[[129, 64, 147, 129],
[ 62, 149, 130, 62],
[149, 130, 62, 149],
...,
当我将其分成各个通道时
ImageFileY = copy.deepcopy(ImageFileYCbCr) # to make a separate copy as array is immutable
ImageFileY[:,:,1] *= 0
ImageFileY[:,:,2] *= 0
ImageFileY[:,:,3] *= 0
ImageFileYOnly = Image.fromarray(ImageFileY)
ImageFileYOnly.show()
这导致了一个红色通道,就像是RGB一样。我该如何分别获取Y、Cb和Cr值?
编辑:Numpy版本为1.3,Python版本为2.6,操作系统为Linux Backtrack 5。
http://www.google.com/url?sa=t&rct=j
中的文档说明不是这样的...” 那个链接带我到了一个空白页面。看着url=
参数,我猜你想链接到这个pdf? - Kevingetbands()
,它会返回('Y', 'Cb', 'Cr')
,而getpixel((0,0))
返回一个有 3 个成员的元组,这表明有 3 个波段。错误一定出现在转换为numpy
的过程中。 - Mark Ransom