API reference¶
Reading & writing¶
Read a flow field from any supported source.
Dispatches on file extension, then magic bytes:
.flo— Middlebury.png— KITTI 16-bit flow.pfm— Sintel / FlyingThings.npy/.npz— saved numpy arrays.flo5/.h5— Spring (requiresh5py)
Non-path inputs (numpy arrays, torch tensors, existing Flow objects)
are normalized via :func:flowiz.core.as_flow.
Write a flow field, choosing the format from path's extension.
Supports .flo (Middlebury), .png (KITTI 16-bit), and .npy.
Convert a torch tensor to a :class:Flow (or list, if batched).
Accepts (H, W, 2), (2, H, W), or a batched (N, 2, H, W) /
(N, H, W, 2) tensor. Batched inputs return a list of flows. The tensor
is detached and moved to CPU automatically.
A dense 2D optical flow field.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
|
valid |
Optional[ndarray]
|
optional |
source |
Optional[str]
|
provenance string (a file path, or |
Visualization¶
Optical flow colorization.
The color mapping is the Baker et al. / Middlebury color wheel, implemented to
be bit-compatible (within +-1 LSB) with the widely used flow_vis package so
that flowiz output matches figures across the literature. See
tests/test_parity.py for the guardrail.
colorize(flow, *, max_flow=None, saturate=True, mask_invalid=True, convention='middlebury', legend=False)
¶
Colorize a flow field into an (H, W, 3) uint8 RGB image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Any
|
a :class: |
required |
max_flow
|
Optional[float]
|
normalization magnitude. |
None
|
saturate
|
bool
|
when |
True
|
mask_invalid
|
bool
|
render pixels flagged invalid (by the flow's |
True
|
convention
|
Convention
|
|
'middlebury'
|
legend
|
bool
|
overlay the color-wheel key in the bottom-right corner. |
False
|
colorize_sequence(flows, *, max_flow='sequence', **kwargs)
¶
Colorize many flows with a shared normalizer (flicker-free video).
max_flow="sequence" (default) computes one normalizer from the max
magnitude across every frame — the fix for v2's per-frame flicker. Pass a
float to fix it explicitly, or None to fall back to per-frame maxima.
flow_to_angle(flow, *, cmap='hsv')
¶
Direction map as an (H, W, 3) uint8 RGB image (angle -> hue).
flow_to_magnitude(flow, *, cmap='magma', max_flow=None)
¶
Magnitude heatmap as an (H, W, 3) uint8 RGB image.
flow_to_uv(flow)
¶
Split flow into a normalized (H, W, 2) uint8 UV image (u, v channels).
make_colorwheel()
cached
¶
Return the (55, 3) uint8 Middlebury color wheel.
Cached — v2 rebuilt this on every frame.
wheel_legend(size=128)
cached
¶
Render the color-wheel key as an (size, size, 4) RGBA uint8 image.
Pixels outside the unit disk are transparent.
Colorize many flows with a shared normalizer (flicker-free video).
max_flow="sequence" (default) computes one normalizer from the max
magnitude across every frame — the fix for v2's per-frame flicker. Pass a
float to fix it explicitly, or None to fall back to per-frame maxima.
Vector (quiver) overlays on top of a colorized flow field.
quiver(flow, *, background=None, step=16, scale=1.0, color=(255, 255, 255), max_flow=None)
¶
Draw flow vectors on a grid over a background image.
Uses matplotlib's quiver for anti-aliased arrows and returns an
(H, W, 3) uint8 RGB image the same size as the input flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Any
|
flow input (Flow / array / tensor). |
required |
background
|
Optional[ndarray]
|
RGB image to draw on. Defaults to the colorized flow. |
None
|
step
|
int
|
grid spacing in pixels between sampled vectors. |
16
|
scale
|
float
|
multiplier on arrow length. |
1.0
|
color
|
tuple[int, int, int]
|
RGB arrow color. |
(255, 255, 255)
|
max_flow
|
Optional[float]
|
passed through to the default colorized background. |
None
|
Render the color-wheel key as an (size, size, 4) RGBA uint8 image.
Pixels outside the unit disk are transparent.
Metrics¶
End-point error between a predicted and ground-truth flow.
EPE is the per-pixel Euclidean distance ||pred - gt||. Summary
statistics are computed over pixels valid in both inputs.
KITTI Fl outlier rate (percent).
A pixel is an outlier when its EPE exceeds 3 px and exceeds 5% of the ground-truth magnitude. Returns the percentage of outliers over valid px.
Build a prediction | ground-truth | error-map figure — the paper money shot.
Normalizes both flow panels by a shared max_flow so colors are
comparable. Annotates EPE / Fl-score in the suptitle. Returns the matplotlib
Figure and, if save is given, writes it to disk.
Batch & video¶
Convert flow files to PNG images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Sequence[str]
|
input flow paths. |
required |
outdir
|
Optional[str]
|
output directory (created if needed). |
None
|
mode
|
str
|
|
'rgb'
|
workers
|
int
|
process-pool size for parallel conversion. |
1
|
progress
|
Optional[Callable[[str], None]]
|
optional callback invoked with each output path as it lands. |
None
|
**kwargs
|
Any
|
forwarded to :func: |
{}
|
Compile flow files into a video (.mp4/.webm/.gif by extension).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
Sequence[str]
|
input flow file paths (any supported format). Sorted naturally. |
required |
output
|
str
|
output video path; the container is inferred from the suffix. |
required |
fps
|
int
|
frames per second. |
24
|
normalize
|
str
|
|
'sequence'
|
max_flow
|
Optional[float]
|
explicit fixed normalizer; overrides |
None
|
quality
|
int
|
imageio quality (0-10) for lossy codecs. |
8
|
progress
|
Optional[Any]
|
optional callable invoked once per frame (e.g. a Rich task update) — receives the 1-based frame index. |
None
|