简体   繁体   English

如何将 24 帧编码为一张 24 位 RGB 图像?

[英]How to encode 24 frames into one 24bit RGB image?

I want to add Blender support for a light field display device.我想为光场显示设备添加 Blender 支持。 The way the display works with standard HDMI cable is the video has each 24bit RGB frame store 24 monochrome frames.显示器使用标准 HDMI 电缆的方式是视频具有每个 24 位 RGB 帧存储 24 个单色帧。 The display splits those frames as it receives them.显示器在接收到这些帧时会对其进行拆分。 Here's an illustration:这是一个插图:

在此处输入图像描述

For this to work, of course, the monochrome frames must be properly encoded in a single 24bit RGB image first.当然,要实现这一点,单色帧必须首先在单个 24 位 RGB 图像中正确编码。 Can PIL, Pillow or another Python library allow to do this? PIL、Pillow 或其他 Python 库可以允许这样做吗?

Not production quality, but probably enough to get you started, I think it must be something like this:不是生产质量,但可能足以让您入门,我认为它必须是这样的:

#!/usr/bin/env python3

from PIL import Image
import numpy as np

w, h = 192, 192

# Create RGB output array h, w, 3
out = np.zeros((h,w,3),dtype=np.uint8)

file = 1
# Iterate over 3 channels, Red, Green and Blue- or maybe B, G, R
for channel in range(3):
    # Iterate over the 8 bits in each channel
    for bitpos in range(8): 
        filename = f"{file}.png"
        print(f"Opening {filename} as bit {bitpos} of channel {channel}")
        im = Image.open(filename).convert('L') 

        # Convert to Numpy image with range 0..1
        ni = (np.array(im)/255).astype(np.uint8)

        # Shift and stuff into output array
        out[...,2-channel] |= ni << (bitpos) 
        file += 1

result = Image.fromarray(out)
result.save('result.png')

Sample Output样品 Output

Opening 1.png as bit 0 of channel 0
Opening 2.png as bit 1 of channel 0
Opening 3.png as bit 2 of channel 0
Opening 4.png as bit 3 of channel 0
Opening 5.png as bit 4 of channel 0
Opening 6.png as bit 5 of channel 0
Opening 7.png as bit 6 of channel 0
Opening 8.png as bit 7 of channel 0
Opening 9.png as bit 0 of channel 1
Opening 10.png as bit 1 of channel 1
Opening 11.png as bit 2 of channel 1
Opening 12.png as bit 3 of channel 1
Opening 13.png as bit 4 of channel 1
Opening 14.png as bit 5 of channel 1
Opening 15.png as bit 6 of channel 1
Opening 16.png as bit 7 of channel 1
Opening 17.png as bit 0 of channel 2
Opening 18.png as bit 1 of channel 2
Opening 19.png as bit 2 of channel 2
Opening 20.png as bit 3 of channel 2
Opening 21.png as bit 4 of channel 2
Opening 22.png as bit 5 of channel 2
Opening 23.png as bit 6 of channel 2
Opening 24.png as bit 7 of channel 2

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM