A vector field as a picture: hue is the direction, value is the length

Description

The convention optical flow has used for twenty years, and a convention rather than a palette decision - which is why it is not in drawing_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.

Usage

flow_to_colours(flow)

Arguments

flow A two-channel vector field: 2 x height x width, channel 1 the row component and channel 2 the column component, which is the layout the engine’s targets use.

Details

What it is for: debugging a separation_flows() model. A field that is right everywhere except reversed looks obviously reversed here and identical in any loss. predict() with type = “channels” is where the field comes from.

A zero vector is black, which is also what the background is, and that is honest - the background has no direction.

Value

A height x width x 3 array of integers, 0-255.

See Also

separation_flows() for the model that predicts one.

Examples

library("rplatypus")

field <- array(0, dim = c(2, 2, 3))
field[1, 1, 1] <- 1   # pointing down
field[2, 1, 2] <- 1   # pointing right
shown <- flow_to_colours(field)
# Two directions, two hues; and no vector, no colour.
!identical(shown[1, 1, ], shown[1, 2, ]) && all(shown[2, 3, ] == 0L)
[1] TRUE