Repurposing vector (speed) render layer for optical flow I'm trying to compute optic flow in my Blender scene using the "speed" render layer (appears as "vector" in the outliner window). This render layer is supposed to return the speed and direction of movement in the scene. Its primary purpose, according to the documentation, is to enable vector blur computation during rendering.

Since this layer is computing what is required for optical flow computation, I would like to output this information as images in HSV color space. In this color space, Hue should be direction of motion (defined in angles around a color circle), and Saturation should be the magnitude of the motion.

There are example of this done with blender, so I know this is possible:
https://www.youtube.com/watch?v=ZmiBI4tPk_o#t=75

However, the output the "speed" render layer is very poorly documented for purposes outside of vector blur. 

My questions are:


How can I tease apart the direction and magnitude information in the
speed layer? 
What are the ranges of these values and how can I remap
them (ie linearly or nonlinearly?) onto values that can make sense
for the output image formats


Here is a .blend file that contains my progress up to a certain point. Tips and ideas are appreciated
Found the solution.
The trick is to enable the desired render layer (ie "vector") and then save the render output as OpenEXR file. That format will save all the desired render layers (in this case, motion information in 4 channels) in a single file, which could then be accessed through various interfaces like Python and Matlab.