uint32
あなたは何を表しているのか混乱していると思います。uint8
整数 の4つのバンドです。
浮動小数点データがあり、それをグレースケールで表現したい場合は、32ビット範囲全体に再スケーリングするのではなく、8ビット範囲に再スケーリングして、赤、緑に対してそれを繰り返します。 、および青いバンド(そしておそらく一定のアルファバンドに入れられます)。
別のバイトオーダーを使用することもできます。Y8
は単一のグレースケール8ビットバンドでありY16
、単一のグレースケール16ビットバンドです。mencoder -rawvideo format=help
(完全な(多少紛らわしいですが)リストの出力を見てください。)
32ビット整数を8ビット整数の4つのバンドとして表示するためにnumpyを使用する方法を説明するために、次のようにします。
import numpy as np
height, width = 20,20
# Make an array with 4 bands of uint8 integers
image = np.zeros((height, width, 4), dtype=np.uint8)
# Filling a single band (red)
b,g,r,a = image.T
r.fill(255)
# Fill the image with yellow and leave alpha alone
image[...,:3] = (255, 255, 0)
# Then when we want to view it as a single, 32-bit band:
image32bit = image.reshape(-1).view(np.uint32).reshape(height, width)
# (Note that this is a view. In other words, we could change "b" above
# and it would change "image32bit")
ただし、あなたの場合は、おそらく次のようなことをしたいと思うでしょう。
import numpy as np
from videosink import VideoSink
height, width = 20,20
numframes = 1000
data = np.random.random((height, width, numframes))
# Rescale your data into 0-255, 8-bit integers
# (This could be done in-place if you need to conserve memory)
d ata_rescaled = 255.0 / (data.max() - data.min()) * (data - data.min())
data_rescaled = data_rescaled.astype(np.uint8)
# The key here is the "Y8" format. It's 8-bit grayscale.
video = VideoSink((height,width), "test", rate=20, byteorder="Y8")
# Iterate over last axis
for frame in data.T:
video.run(frame.T)
video.close()