Camera-subset alignment (track.align_4cam, opt-in)¶
In short
With a calibration that is a little off, a particle seen by 3 cameras is placed a little differently from the same particle seen by 4. Along a track that shows up as a sideways jump every time the set of cameras changes, and as noise in velocity and acceleration. track.align_4cam: true removes that jump. It does not touch the camera files, does not touch any 4-camera position, and is off by default.
The problem in plain words¶
A real calibration is never exact: the four lines of sight to one particle miss each other by a fraction of a pixel (0.2 to 0.4 px on our real data).
- While a particle is seen by all four cameras, that miss is almost the same from frame to frame, so it cancels when you subtract two positions to get a velocity.
- When one camera drops out (a 3-camera point; on
test_cavitythree quarters of the points), the three remaining lines meet at a slightly different place. The position jumps, by about the size of the calibration error, and the jump does not cancel.
What it does¶
- It takes the clean 4-camera points (no shared blob) and measures, per camera, what is left over between the blob centre and where the 4-camera position projects. That leftover is the calibration error, and it varies smoothly in space.
- It fits a smooth function of position to it (a cubic polynomial, per camera, robust to a few bad points).
- For every point seen by 2 or 3 cameras it subtracts that function from the blob centres and triangulates again.
4-camera points are not changed: by the least-squares equations of triangulation, subtracting this field leaves them where they are.
It changes consistency, not absolute position. The 4-camera positions keep whatever error the calibration has. What goes away is the difference between the 3-camera and the 4-camera position of the same particle. For velocities, that difference is what matters. If you need the camera files themselves improved, use self-calibration.
How to use it¶
It is off by default, and it helps only in some cases (see "When to turn it on" below). Turn it on for one run, compare with the run without it, and keep it only if it helps.
In YAML (parameters_Run1.yaml, any tracker):
On the command line: openptv2-batch ... --align-4cam (--no-align-4cam forces it off).
In the GUI: open Tracking Parameters, group Pipeline, tick Align 4-camera subsets (fixes 3-cam calibration jumps for all trackers), and save. The box is unticked by default.
It runs once before the tracker and needs at least 100 clean 4-camera points (otherwise it does nothing).
When to turn it on¶
Alignment removes one specific defect: a position jump on links where the particle's set of cameras changes. So it matters in proportion to two things, the size of the jump and the share of links that change camera set. It does not make tracks longer by itself and does not improve absolute accuracy.
Turn it on when both hold:
- The calibration check shows a jump above about 0.05 px (
python -m openptv2.calibration_consistency check <run>saysmarginalorinconsistent), and the held-out check improves (scripts/align4cam_loco.py, see the checklist below). - A fair share of your links change camera set. Count them with
python scripts/align4cam_share.py <run>(no truth needed). On our benchmark about 10 % of links change set, on real wp2 12.8 %, on lv_multi wp5 15.9 %. A share of a few percent leaves little to gain.
A large calibration error with most points seen by all cameras gives little, because few links change set. A perfect calibration gives nothing.
What it did in our tests: link errors change only on the links where the set changes (the others are identical to three decimals); about two thirds of the jump goes at a benchmark-sized calibration error, and the velocity error falls by a few percent (about 10 % at twice that error). On real wp2 the held-out error fell 42 % (0.350 to 0.201 px), so the correction is real; how much it improves wp2 velocities we could not verify, because real data has no truth.
Where the result is stored¶
The measured positions in correspondences/ are never overwritten. The aligned positions go to a separate array, correspondences_aligned/, and RunStore.read_correspondences(frame) returns them in place of the measured ones. read_correspondences(frame, raw=True) returns the measured ones, and RunStore.clear_aligned_positions() removes the aligned ones.
- Running it twice gives the same result: the fit always starts from the measured positions.
- A run with
align_4cam: falseremoves aligned positions left by an earlier run, so it uses the measured ones. - A step that rewrites a frame's correspondences (for example a ghost filter that removes rows) drops that frame's aligned copy.
- The explicit repair
python -m openptv2.calibration_consistency align(recipe) is a different thing: it rewrites the stored positions in place and records that in the store. It is unchanged. A run withalign_4cam: falsedoes not undo it. trackcorrandfast_3dwrite each frame back as they always did, with or without this option. With the option on, they write the aligned values for the frames they change.
Why it helps, and why the gain is small¶
A velocity is a difference of two positions, so only an error that is different at the two ends of a link survives. We split every link of a truth benchmark run by what happens to the camera set along it (scripts/align4cam_link_split.py; error of the measured step against the true step, rms in mm, benchmark-size calibration error, two_phase):
| Link type | Share of links | Without | With alignment |
|---|---|---|---|
| all 4 cameras at both ends | 67 % | 0.067 | 0.067 |
| the same 3 cameras at both ends | 23 % | 0.079 | 0.079 |
| the camera set changes | 10 % | 0.120 | 0.112 |
- Links that keep their cameras are untouched. The calibration error is smooth in space, so it is nearly the same at both ends of the link and cancels. There is nothing to remove, and alignment changes these numbers by less than the third decimal.
- Links where the set changes carry the calibration error as a jump. With no calibration error at all, these links are still worse (0.111): fewer cameras means a noisier position, and alignment cannot help that. The extra error above that floor is the jump: 0.046 mm without alignment, 0.015 mm with it, so about two thirds of the jump goes. At twice the calibration error the jump doubles (0.089) and alignment removes about half (0.043 left).
- Why the total gain is small. Only about 10 % of links change their camera set, so removing two thirds of their extra error lowers the whole-run link error by about 1.5 %. After smoothing, the velocity error falls by a few percent. It is a fix for a specific, rare defect, not a general improvement.
What this predicts, and what we saw:
| Situation | Prediction | Result |
|---|---|---|
| perfect calibration | no jump, no gain | link errors identical to three decimals |
| larger calibration error | jump grows, gain grows | jump 0.046 → 0.089 mm; velocity gain 5 % → 11 % |
| larger frame step | the jump stays the same size in mm, but the true step is 4 times longer, so it matters less; no loss | jump 0.116 → 0.108 mm against a 0.4 mm step, no loss |
| twice the particles | the same defect, only more of it; more merged blobs, so the shared floor (noise) is higher | jump removal unchanged (0.131 → 0.122 mm); gain within noise |
| it closes gaps? | a few more links, because the tracker sees a smoother track | +1.7 % links among those that change camera set, +0.1 % overall |
So alignment does close some gaps, but few: its job is to take the step out of the track, not to make long tracks. Where a trajectory crosses the edge of the domain and loses a camera, the jump is real and removed. It does not matter often enough, per link, to change the track statistics much.
Should you try it? A checklist¶
Run these two checks on your finished sequence step (they read the run and write nothing):
python -m openptv2.calibration_consistency check <run> # verdict, worst jump, "field reproducible"
python scripts/align4cam_loco.py <run> --frames 100 # held-out error before and after the alignment
| You see | Recommendation |
|---|---|
| fewer than 4 cameras | not applicable |
verdict consistent (jump below 0.05 px), or the held-out error does not change |
leave it off: there is nothing systematic to remove. On a perfect calibration it changes nothing |
marginal or inconsistent, "field reproducible" 20 % or more in at least two cameras, held-out error down by 20 % or more |
try it: run the tracking with and without, and compare the number of long tracks and links |
"field reproducible" near 0 % (test_cavity: 0 to 3 %) |
leave it off: the error is not a smooth field, so a smooth correction cannot remove it (held-out gain only 7 %) |
| worst jump above about 1 px, or the matching keeps few 4-camera points | re-calibrate first (self-calibration): at four times the benchmark's error, tracking itself failed (yield 0.37 against 0.68) and alignment did not help |
The thresholds are rules of thumb from three real datasets and one synthetic benchmark, not tuned limits. What to expect when it does apply, from our truth benchmark (below): a few percent lower velocity error at a benchmark-sized calibration error, about 10 % at twice that, one to two points more of the true long tracks, and about half a point more correct links. The leave-one-camera-out number overstates this: it fell 28 to 76 % in the same cases.
Real data¶
Held-out leave-one-camera-out median error (fit on every other frame), the consistency check, and what alignment did to the tracks:
| Data | Check verdict, worst jump | Field reproducible | Held-out error | Tracks |
|---|---|---|---|---|
CompleteTest wp2, 100 / 200 frames |
marginal, 0.13 px | 43 to 51 % | 0.350 → 0.201 px (−42.5 %) | two_phase, 200 frames: mean length 6.15 → 6.41, tracks of 50+ frames 1037 → 1082 (+4 %), links +0.8 % |
lv_multi wp5, 20 frames |
marginal, 0.14 px | 25 to 43 % | 0.400 → 0.262 px (−34.5 %) | not run |
test_cavity, 5 frames |
marginal, 0.25 px | 0 to 3 % | 1.307 → 1.213 px (−7 %) | 152 against 153 trajectories |
On real data there is no truth, so these show consistency and track length, not that every added link is right.
Benchmark with truth (L1: rendered blobs with merges, false targets, dropouts)¶
scripts/synth_bench.py with SYNTH_BENCH_CAL_SCALE multiplying the calibration error of the Synthetic-CompleteTest images (1 = that error), 60 frames, about 1500 particles per frame, 16 % of blobs missing. Change of the velocity error with align_4cam on (negative is better; one seed, the other seeds are in the study record):
| Calibration error | consistency check | two_phase |
fast_3d |
trackcorr |
|---|---|---|---|---|
| none (×0) | consistent, 0.01 px | 0 % | 0 % | −1 % |
| ×0.5 | marginal, 0.23 px | −5 % | 0 % | −4 % |
| ×1 (the images' own) | inconsistent, 0.46 px | −5 % (−1 to −2 % on two more seeds) | −9 % | −2 % |
| ×2 | inconsistent, 0.92 px | −11 % (−8 and −12 %) | −10 % | −8 % |
| ×4 | few matches survive | +3 % (worse) | −5 % | −7 % |
| ×1, twice the density | −3 % (−2 to −3 % on 3 seeds) | −2 % | +9 % on this seed, but −7 % and −3 % on two more: about 0 on average | |
| ×2, twice the density | −9 % | −11 % | −8 % | |
| ×1, step of 4 frames | +4 % on this seed, but −6, −4 and −12 % on three more: about −4.5 % on average | −3 % | −9 % | |
| ×2, step of 4 frames | −8 % | −5 % | 0 % |
At ×2 with two_phase: share of correct links 0.936 → 0.941, long tracks kept whole 0.565 → 0.580, pieces per long track 1.31 → 1.26. The velocity error is on all points each run found, so a few cases mix a small yield change into it.
Reading it: the gain follows the size of the calibration error, is similar for all three trackers, and disappears when the error is so large that matching itself breaks down. One seed moves the velocity error by several percent either way (the single reversals in the table are noise: they vanish on other seeds), so differences below about 5 % at the benchmark error are not resolved. The gain at twice the density looks smaller (−2 to −3 % for two_phase) but that is within that noise.
Truth test of the geometry¶
scripts/synthetic_align4cam.py (run by tests/unit/test_align4cam_truth.py) projects points with known positions through the true cameras, then processes them with spoiled cameras. RMS in mm; jump is the difference between the 3-camera and 4-camera position of the same particle:
| Case | jump before → after |
|---|---|
| no calibration error | 0.020 → 0.020 (no change, no harm) |
| calibration error | 0.995 → 0.047 |
| three times larger | 2.999 → 0.157 |
| noise 0.3 px | 0.995 → 0.073 |
| 5 % gross errors among the fit points | 0.985 → 0.049 |
| only 150 fit points | 0.991 → 0.050 |
| fitted on the inner 40 % of the volume, evaluated outside | 1.002 → 0.052 |
The 3-camera error against the truth falls to the level of the 4-camera error, and not below it.
Limits¶
- It only moves points seen by fewer than all cameras. With 4 cameras and 4-camera points everywhere it does nothing.
- Three-camera points move by the calibration error, which can be large along the depth direction when the three cameras are on one side. On
test_cavity, the median move is 0.12 mm and the largest 3.5 mm. - The field is smooth (cubic). A calibration error with sharp structure is only partly removed.
- Absolute accuracy is not improved.
Related, measured elsewhere¶
Two other changes were proposed together with this one in the pull request that introduced it, and are not part of the default behaviour: refine_merged(prior=False) (no quadratic path prior), and log_brightness_from_arrays(mask_shared=True) (the ghost filter ignores shared blobs when comparing brightness). Both exist as options. The synthetic benchmark numbers of that pull request (velocity error −2 % to −21 %) were measured with all three on, and have not been re-run separately.