basicsr.utils.flow_util¶
- basicsr.utils.flow_util.dequantize(arr, min_val, max_val, levels, dtype=<class 'numpy.float64'>)[source]¶
Dequantize an array.
- Parameters:
arr (ndarray) – Input array.
min_val (scalar) – Minimum value to be clipped.
max_val (scalar) – Maximum value to be clipped.
levels (int) – Quantization levels.
dtype (np.type) – The type of the dequantized array.
- Returns:
Dequantized array.
- Return type:
tuple
- basicsr.utils.flow_util.dequantize_flow(dx, dy, max_val=0.02, denorm=True)[source]¶
Recover from quantized flow.
- Parameters:
dx (ndarray) – Quantized dx.
dy (ndarray) – Quantized dy.
max_val (float) – Maximum value used when quantizing.
denorm (bool) – Whether to multiply flow values with width/height.
- Returns:
Dequantized flow.
- Return type:
ndarray
- basicsr.utils.flow_util.flowread(flow_path, quantize=False, concat_axis=0, *args, **kwargs)[source]¶
Read an optical flow map.
- Parameters:
flow_path (ndarray or str) – Flow path.
quantize (bool) – whether to read quantized pair, if set to True, remaining args will be passed to
dequantize_flow()
.concat_axis (int) – The axis that dx and dy are concatenated, can be either 0 or 1. Ignored if quantize is False.
- Returns:
Optical flow represented as a (h, w, 2) numpy array
- Return type:
ndarray
- basicsr.utils.flow_util.flowwrite(flow, filename, quantize=False, concat_axis=0, *args, **kwargs)[source]¶
Write optical flow to file.
If the flow is not quantized, it will be saved as a .flo file losslessly, otherwise a jpeg image which is lossy but of much smaller size. (dx and dy will be concatenated horizontally into a single image if quantize is True.)
- Parameters:
flow (ndarray) – (h, w, 2) array of optical flow.
filename (str) – Output filepath.
quantize (bool) – Whether to quantize the flow and save it to 2 jpeg images. If set to True, remaining args will be passed to
quantize_flow()
.concat_axis (int) – The axis that dx and dy are concatenated, can be either 0 or 1. Ignored if quantize is False.
- basicsr.utils.flow_util.quantize(arr, min_val, max_val, levels, dtype=<class 'numpy.int64'>)[source]¶
Quantize an array of (-inf, inf) to [0, levels-1].
- Parameters:
arr (ndarray) – Input array.
min_val (scalar) – Minimum value to be clipped.
max_val (scalar) – Maximum value to be clipped.
levels (int) – Quantization levels.
dtype (np.type) – The type of the quantized array.
- Returns:
Quantized array.
- Return type:
tuple
- basicsr.utils.flow_util.quantize_flow(flow, max_val=0.02, norm=True)[source]¶
Quantize flow to [0, 255].
After this step, the size of flow will be much smaller, and can be dumped as jpeg images.
- Parameters:
flow (ndarray) – (h, w, 2) array of optical flow.
max_val (float) – Maximum value of flow, values beyond [-max_val, max_val] will be truncated.
norm (bool) – Whether to divide flow values by image width/height.
- Returns:
Quantized dx and dy.
- Return type:
tuple[ndarray]