python - 将 Ycbcr 的不同 channel 保存为单独的图像 | Python

标签 python python-imaging-library color-space

我需要对 Ycbcr 颜色空间的各个 channel 应用一些转换。

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

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()

关于python - 将 Ycbcr 的不同 channel 保存为单独的图像 | Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39939595/

相关文章:

python - 从数据流而不是文件加载图像

css - 使用 CSS 过滤器模拟 Photoshop 的 "Color Overlay"?

python - 我可以检查 sqlalchemy 查询对象以查找已连接的表吗?

python - 使用 Argparse 在 Python 中创建文件转换器

python - 调整列表的 numpy 数组的大小,以便所有列表都具有相同的长度,并且可以正确推断 numpy 数组的 dtype

python - ImportError:无法从 'is_directory' 导入名称 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py)

python - 将bmp转换为tiff,python

python - OpenCV 错误:(-215:断言失败)函数 'CvtHelper' 中的 VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth)

opencv - 应用平滑过滤器(双边、高斯、vs.)和色彩空间

python - 从 pandas 系列列表中获取唯一值