flow_to_colours
flow_to_colours(flow)A two-channel vector field as a picture: hue is the direction, value is the length.
The convention optical flow has used for twenty years, and it is a convention rather than a palette decision - which is why it is not in pyplatypus.style. Nothing about it is a choice this project gets to make differently from everyone else’s figures, and a reader who has seen one flow visualisation can read this one.
Without it, debugging a flows separation (#212) or hv (#213) means reading arrays. A field that is right everywhere except reversed looks obviously reversed here and identical in any loss.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| flow | np.ndarray | (2, height, width), channel 0 the row component and channel 1 the column component - the layout flows_from_instances returns. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | A height x width x 3 array of 0-255 integers. A zero vector is black, which is |
|
| np.ndarray | also what the background is, and that is honest: the background has no direction. |
Raises
| Name | Type | Description |
|---|---|---|
| PlatypusError | if the array is not a two-channel field. |
import numpy as np field = np.zeros((2, 2, 3)) field[0, 0, 0] = 1.0 # pointing down field[1, 0, 1] = 1.0 # pointing right shown = flow_to_colours(field) shown.shape (2, 3, 3) bool((shown[0, 0] != shown[0, 1]).any()) # two directions, two hues True tuple(int(channel) for channel in shown[1, 2]) # no vector, no colour (0, 0, 0)