Emulating iToF Measurements

This tutorial covers indirect time-of-flight (iToF) emulation: turning rendered depth and albedo frames into raw per-tap sensor measurements, and decoding those measurements back into depth. See the sensor section for the underlying model.


Prerequisites

You need a rendered sequence with both albedo frames and depth maps. The Quick Start and the Large Scale Datasets tutorial both produce one.

The Blender renderer writes albedo and depth to sibling directories, each with its own metadata, so the emulator takes a path for each. If you already combined them into one dataset with dataset.merge, a single --input-dir is enough and each frame’s depth is read from its depth_file_path.


Emulating Measurements

Run the emulator over a rendered sequence:

visionsim emulate.itof \
    --input-dir=renders/lego-gt/frames \
    --depth-dir=renders/lego-gt/depths \
    --output-dir=renders/itof \
    --scheme=convSin --n-captures=4 --freq=120e6

The scheme, the number of captures --n-captures and the modulation frequency --freq define the acquisition. With --scheme=deltaHilbertDimTwo (or any other Hilbert scheme) the curve parameters can be adjusted with --hilbert-order and --hilbert-delta, and multi-frequency coding needs the per-tap vectors:

visionsim emulate.itof --input-dir=renders/lego-gt/frames --depth-dir=renders/lego-gt/depths \
    --output-dir=renders/itof --scheme=multFreqSin --n-captures=5 \
    --freq-vec 1 1 1 2 2 --shifts-vec 0 2.094 4.189 0 1.571

Each frame writes a .npy array of shape (n_captures, H, W) holding the raw measurements of the n_captures taps. The output params.json records the acquisition parameters (scheme, captures, frequency and the unambiguous range), which is what lets you decode the arrays later without guessing how they were produced. Use --preview to also dump a colorized PNG per tap, and --force to overwrite an existing output directory.

The CLI warns when the scene contains depths beyond the unambiguous range of the selected scheme. That range is c/2f for most schemes and c/4f for the ramp schemes, and geometry past it folds back into the recovered depths while the radiometric falloff keeps following the true distance. In the lego scene the truck sits around 4.5-5.8 m against a 1.25 m range at f = 120 MHz, so every scheme folds there; the ramp schemes fold at 0.62 m instead.

Note

iToF sensors are monochromatic, so color albedo frames are converted to linear luma before the correlation is computed.


Frequency and Folding

The modulation frequency sets the unambiguous range (usually c/2f), so the same room folds differently across a frequency sweep. The figure below runs convSin with four captures at 40, 60, 80 and 120 MHz, one frequency per column: the top row is tap 0 of the four captures, the bottom row is the depth decoded from all four, and the single colorbar is shared across the sweep and spans the widest range.

The room is 3.34 m deep, so the 40 MHz range of 3.75 m recovers it whole; each step up folds more of it, and 120 MHz wraps it several times over in 1.25 m. Tap 0 shows the same folding as progressively finer fringes.

../_images/sweep.webp
../_images/sweep-dark.webp

convSin at 40, 60, 80 and 120 MHz: tap 0 above, decoded depth below, on a shared depth scale.

The sensor section derives the model behind this and lists the frequencies and capture counts each decoder accepts.


Decoding Measurements

Decoding is available through the Python API, which lets you exercise a coding scheme without rendering a scene first:

import numpy as np
import scipy.constants
from visionsim.emulate.itof import decode, make_coding_functions, simulate_measurements

freq = 120e6
period = 1 / freq                               # one code period
d_max = scipy.constants.c * period / 2          # range it wraps over, ~1.25 m

modulation_codes, reference_codes = make_coding_functions("convSin", 4, 1001)
depths = np.linspace(0.05, d_max - 0.05, 64)
measurements = simulate_measurements(
    depths, np.full_like(depths, 0.8), modulation_codes, reference_codes, period
)
recovered = decode("convSin", measurements, freq)

print(np.abs(recovered - depths).max())        # sub-millimetre for every depth

To decode emulated frames with decode(), load them and flatten the spatial dimensions:

import numpy as np
from visionsim.emulate.itof import decode

measurements = np.load("renders/itof/0000.npy")           # (n_captures, H, W)
k, height, width = measurements.shape
depths = decode("convSin", measurements.reshape(k, -1), freq=120e6).reshape(height, width)

Warning

The capture count must match the scheme; the scheme table in the sensor section lists the counts each decoder accepts. multFreqSin additionally needs the same freq_vec and shifts_vec that were used during acquisition.

When the scheme is known up front, the matching decoder can be called directly instead of going through the dispatcher: decode_sinusoid() (convSin, deltaSin), decode_square() (convSquare), decode_single_ramp() and decode_double_ramp() (the ramp schemes), decode_hilbert() (the Hilbert schemes) and decode_mult_freq_sinusoid() (multFreqSin).