【发布时间】:2014-07-07 12:35:50
【问题描述】:
嗯,标题很容易解释。我有一个图像文件,我想分别分成 Y、Cb 和 Cr。打开文件后,将其从RGB(打开图像文件时的默认模式)转换为YCbCr,然后使用numpy.array()将其转换为数组,结果是一个4通道的二维数组,这不是根据http://www.nmt.edu/tcc/help/pubs/pil/pil.pdf中的文档,我期望
这是我在解释器中所做的:
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=参数,我猜你的意思是链接到this pdf? -
看看这里:stackoverflow.com/questions/2797102/… 这可能会有所帮助
-
哦,你说得对,凯文。我会编辑它。谢谢。
-
如果我在图像上调用
getbands(),它会返回('Y', 'Cb', 'Cr'),而getpixel((0,0))返回一个包含3 个成员的元组,表示3 个波段。错误必须在转换为numpy。 -
有什么建议吗,马克?
标签: python python-imaging-library