我需要对Ycbcr颜色空间的各个通道进行一些转换。

我有一个tiff格式的图像作为源,我需要将其转换为ycbcr颜色空间。我无法将不同的频道成功保存为单独的图像。我只能使用以下代码提取发光通道:

import numpy
import Image as im
image = im.open('1.tiff')
ycbcr = image.convert('YCbCr')

B = numpy.ndarray((image.size[1], image.size[0], 3), 'u1', ycbcr.tobytes())
im.fromarray(B[:,:,0], "L").show()


有人可以帮忙吗?

谢谢

最佳答案

这是我的代码:

import numpy
import Image as im
image = im.open('1.tiff')
ycbcr = image.convert('YCbCr')

# output of ycbcr.getbands() put in order
Y = 0
Cb = 1
Cr = 2

YCbCr=list(ycbcr.getdata()) # flat list of tuples
# reshape
imYCbCr = numpy.reshape(YCbCr, (image.size[1], image.size[0], 3))
# Convert 32-bit elements to 8-bit
imYCbCr = imYCbCr.astype(numpy.uint8)

# now, display the 3 channels
im.fromarray(imYCbCr[:,:,Y], "L").show()
im.fromarray(imYCbCr[:,:,Cb], "L").show()
im.fromarray(imYCbCr[:,:,Cr], "L").show()

10-06 10:34