6

だから、これはこのスレッドへのコメントであるはずですが、明らかに閉じているので、ここに行きます。この辺りで提案されているように、私はmatplotlibとnumpyとmencoderでかなりうまく遊んでいます。それ以来、私はVokiCodderバッファーをstdinソリューションに採用しました、これによりプロセス全体が大幅に高速化されます。問題は、コマンドの-format="bgra"部分にドキュメントが見つからなかったことです。これは、バイトが右から左に青、緑、赤のアルファ、右にあることを意味します。それらはuint32か何か他のものでなければなりませんか?問題は、フロートのカラーマップをプロットしているので、それらをグレースケールに変換しようとしていますが、何か間違ったことをしていると強く信じさせる奇妙なパターンがたくさんあります。この関数は、範囲内でfloatからuint32に変換するために作成しました。しかし、結果は私が期待した理由ではありません、私はひどく愚かなことをしていますか?

def grayscale(x, min, max):
  return np.uint32((x-min)/(max-min)*0xffffff)
4

1 に答える 1

5

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()
于 2011-08-12T19:07:33.337 に答える