So, this should be a comment to this thread, but it’s apparently closed, so here it goes. I’ve been playing around quite successfully with matplotlib and numpy and mencoder, as has been suggested around here. I have since adopted Voki Codder buffer to stdin solution, which speeds the whole process up considerably. The thing is, I couldn’t find any documentation on the -format=”bgra” part of the command. This means that the bytes are from right to left blue green red alpha, right. Do they have to be uint32, or something else. The problem is I’m plotting colormaps of floats, so I’m trying to convert them to grayscale, but I’m getting lots of weird patterns which make me strongly believe I’m doing something wrong. I wrote this function to convert from floats to uint32 within a range. But the result is not why I expected, am I doing something terribly stupid?
def grayscale(x, min, max):
return np.uint32((x-min)/(max-min)*0xffffff)
I think you’re getting confused on what the
uint32represents. It’s 4 bands ofuint8integers.If you have floating point data, and want to represent it in grayscale, you don’t want to rescale it to a full 32 bit range, you want to rescale it to an 8-bit range, and repeat that for the red, green, and blue bands (and then presumably put in a constant alpha band).
You could also just use a different byteorder.
Y8is just a single grayscale, 8-bit band, andY16is a single, grayscale 16-bit band. (Have a look at the output ofmencoder -rawvideo format=helpfor a full (though somewhat confusing) listing.)Just to illustrate using numpy for view a 32-bit integer as four bands of 8-bit integers:
In your case, however, you probably want to do something more like this: