Definitioncore
Feature track
Also called point track, multiview correspondence.
The set of image features in several views that show one scene point, built by joining pairwise matches, often with union-find.
A feature track is the set of image features, at most one in each image, that show the same scene point. It is the unit of data of structure from motion: one track becomes one 3D point, and each feature in it becomes one observation of that point. Matching gives only pairs of features, one pair for each image pair, so the tracks are built by joining the pairs: two pairs that share a feature belong to the same track. In graph terms, a track is a connected component of the match graph, and union-find computes all components in near-linear time. A component that holds two features of the same image cannot be one scene point, so it is marked inconsistent and is split or dropped. In a video, a tracker such as the Kanade-Lucas-Tomasi tracker follows each feature from frame to frame, and the tracks come directly from the tracker.
Definition
Features, matches and tracks
A feature is a pair : the keypoint with index in image , with its pixel position . A match is a pair of features with that the feature matching step, usually followed by a geometric check, accepts as images of one scene point.
The match graph has the matched features as vertices and the matches as edges. A track is the vertex set of one connected component of the match graph. The length of the track is . A track is consistent if no image occurs twice in it, that is, if the map is one to one on . Only consistent tracks are passed to reconstruction, where a consistent track gives the unknown point and one observation for each .
BUILD-TRACKS(matches)- 1
for each match (a, b) in matches - 2
MAKE-SET(a) and MAKE-SET(b), if they are new - 3
UNION(a, b) - 4
for each feature f in the forest - 5
add f to the group of FIND(f) - 6
for each group T - 7
consistent(T) <- (no two features of T have the same image) - 8
return all groups T, each with its flag consistent(T)
Lines L1 to L3 run union-find with union by size and path halving over the matches, and lines L4 and L5 collect the components. Line L7 is the consistency test. The caller keeps the consistent tracks and drops or splits the others.
Examples and non-examples
- A chain. The matches to and to give the track of length 3, which is consistent. The pair and was never matched directly, but it is still in the track; this is how tracks become longer than the pairs that make them.
- A non-example: an inconsistent component. Add the matches to , to and to . Their component is . Two features of image are in it, so it is not a track of one point: one of the matches is wrong, or two features of image sit on the same scene point. The reference code returns exactly these two groups, the first marked consistent and the second not.
- A video track. In a video, a keypoint followed by a tracker through frames to gives one track of length 10 with one feature in each frame. It is consistent by construction.
- A non-example: an unmatched feature. A keypoint that is in no match is not in the match graph, so it is in no track. A track needs at least two views, because one view does not fix the depth of a point.
- A non-example: a match that is not a track. A pair that the geometric check rejected is not an edge, so it joins nothing, even if the descriptors are close.
Related definitions
- Match graph and view graph. The match graph has features as vertices. The view graph has images as vertices and an edge for each image pair with enough verified matches; it is the match graph seen at the level of images.
- Connected components and union-find. A track is a connected component; the disjoint-set forest builds all of them with unions in time for matches.
- Observation. One feature of a consistent track is one observation of its 3D point, which enters the reprojection error and bundle adjustment.
- Measurement matrix. When every track has a feature in every image, the tracks fill the measurement matrix of the Tomasi-Kanade and Sturm-Triggs factorization methods.
- Triangulation. The 3D point of a track is found by point triangulation from its features and the camera poses.
Proof: BUILD-TRACKS returns the connected components of the match graph with the right consistency flagsfull
We use the notation of the page. The match graph has the matched features as vertices and the matches as edges. Let be the graph on the same vertices with only the first matches as edges.
Claim. BUILD-TRACKS returns one group for each connected component of , the group holds exactly the features of that component, and its flag is true if and only if no image occurs twice in it.
Cost. There are at most vertices for matches. With union by size and path halving, the operations of lines L1 to L5 take time, where is the inverse Ackermann function (Tarjan and van Leeuwen). Line L7 takes time linear in the size of the group with a hash set, so the whole run takes expected time and space.
Invariant. After line L3 has run for the first matches, two features and that have been added have the same root, , if and only if they are connected in .
Proof of the invariant. For no feature has been added, so the claim is empty. Assume it for , and let the match be . Line L2 adds and as singleton sets if they are new; a new feature has no edge in , so it is alone in its component, and it is alone in its set, which keeps the invariant. Line L3 then calls . Union by size makes one of the two roots a child of the other and changes no other parent pointer, and path halving only moves a pointer to a node higher on the same path, so it keeps every root. So after the union the sets are those before, with the set of and the set of merged into one. In the graph, adding the edge merges the component of and the component of and leaves the others as they are. By the induction hypothesis, the sets before the union were the components of on the added features, so the sets after the union are the components of .
Proof of the claim. After the loop of lines L1 to L3, every vertex of has been added, because every vertex is an end of some match, and by the invariant with , two vertices have the same root if and only if they are connected in . Lines L4 and L5 put each vertex into the group of its root. So two vertices are in the same group if and only if they are in the same component, and each group is exactly one component. Line L7 compares the number of distinct images in the group with the size of the group. These two numbers are equal if and only if the map from a feature to its image is one to one on the group, which is the definition of a consistent track. Line L8 returns every group with its flag.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/feature-track/. The authors are listed in prov/MRQ8VT.jsonl.
"""Feature tracks from pairwise matches, by union-find.
A feature is a pair (image, index). A match is a pair of features, one in
each of two images, that are thought to show the same 3D point. A track
is a connected component of the match graph, whose nodes are the
features and whose edges are the matches. A track is consistent if no two
of its features are in the same image; an inconsistent track joins two
different points (or one point seen twice in one image) and must be split
or dropped before reconstruction.
"""
from typing import Dict, Hashable, Iterable, List, Tuple
Feature = Tuple[Hashable, int]
Match = Tuple[Feature, Feature]
class DisjointSet:
"""Union-find with path halving and union by size."""
def __init__(self) -> None:
self.parent: Dict[Feature, Feature] = {}
self.size: Dict[Feature, int] = {}
def add(self, x: Feature) -> None:
if x not in self.parent:
self.parent[x] = x
self.size[x] = 1
def find(self, x: Feature) -> Feature:
p = self.parent
while p[x] != x:
p[x] = p[p[x]]
x = p[x]
return x
def union(self, a: Feature, b: Feature) -> None:
ra, rb = self.find(a), self.find(b)
if ra == rb:
return
if self.size[ra] < self.size[rb]:
ra, rb = rb, ra
self.parent[rb] = ra
self.size[ra] += self.size[rb]
def build_tracks(matches: Iterable[Match]) -> List[Tuple[List[Feature], bool]]:
"""Return the tracks as (sorted list of features, consistent), sorted by
their first feature. Features that appear in no match give no track."""
ds = DisjointSet()
for a, b in matches: # @line L1
ds.add(a) # @line L2
ds.add(b)
ds.union(a, b) # @line L3
groups: Dict[Feature, List[Feature]] = {}
for f in ds.parent: # @line L4
groups.setdefault(ds.find(f), []).append(f) # @line L5
tracks = []
for members in groups.values(): # @line L6
images = [img for img, _ in members]
consistent = len(set(images)) == len(images) # @line L7
tracks.append((sorted(members, key=repr), consistent))
tracks.sort(key=lambda t: repr(t[0][0]))
return tracks # @line L8
def split_by_image(track: List[Feature]) -> Dict[Hashable, List[int]]:
"""The features of a track, grouped by image."""
out: Dict[Hashable, List[int]] = {}
for img, idx in track:
out.setdefault(img, []).append(idx)
return out
test_feature_track.py 86 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/feature-track/. The authors are listed in prov/MRQ8VT.jsonl.
import random
from feature_track import DisjointSet, build_tracks, split_by_image
def components_by_search(matches):
adj = {}
for a, b in matches:
adj.setdefault(a, set()).add(b)
adj.setdefault(b, set()).add(a)
seen, comps = set(), []
for s in adj:
if s in seen:
continue
stack, comp = [s], []
seen.add(s)
while stack:
x = stack.pop()
comp.append(x)
for y in adj[x]:
if y not in seen:
seen.add(y)
stack.append(y)
comps.append(frozenset(comp))
return set(comps)
def test_chain_of_matches_is_one_track():
matches = [((0, 4), (1, 7)), ((1, 7), (2, 1)), ((2, 1), (3, 9))]
tracks = build_tracks(matches)
assert tracks == [([(0, 4), (1, 7), (2, 1), (3, 9)], True)]
def test_two_features_in_one_image_make_an_inconsistent_track():
matches = [((0, 4), (1, 7)), ((1, 7), (2, 1)), ((2, 1), (0, 5)), ((3, 0), (4, 0))]
tracks = build_tracks(matches)
assert len(tracks) == 2
bad = [t for t, ok in tracks if not ok]
assert bad == [[(0, 4), (0, 5), (1, 7), (2, 1)]]
assert split_by_image(bad[0])[0] == [4, 5]
def test_random_matches_agree_with_graph_search():
rng = random.Random(3)
for _ in range(20):
n_img, n_feat = rng.randint(2, 6), rng.randint(1, 8)
matches = []
for _ in range(rng.randint(0, 30)):
a, b = rng.sample(range(n_img), 2)
matches.append(((a, rng.randrange(n_feat)), (b, rng.randrange(n_feat))))
tracks = build_tracks(matches)
assert {frozenset(t) for t, _ in tracks} == components_by_search(matches)
for t, ok in tracks:
imgs = [i for i, _ in t]
assert ok == (len(imgs) == len(set(imgs)))
def test_match_order_does_not_matter():
rng = random.Random(4)
matches = [((rng.randrange(5), rng.randrange(6)), (rng.randrange(5, 9), rng.randrange(6)))
for _ in range(25)]
first = build_tracks(matches)
for _ in range(5):
rng.shuffle(matches)
assert build_tracks(matches) == first
def test_union_by_size_keeps_trees_shallow():
ds = DisjointSet()
nodes = [(0, k) for k in range(1024)]
for x in nodes:
ds.add(x)
for k in range(1, 1024):
ds.union(nodes[k - 1], nodes[k])
# union by size alone bounds the depth by log2(1024) = 10
depth = 0
for x in nodes:
d = 0
while ds.parent[x] != x:
x = ds.parent[x]
d += 1
depth = max(depth, d)
assert depth <= 10
References
- Noah Snavely, Steven M. Seitz and Richard Szeliski, Photo tourism: exploring photo collections in 3D, ACM Transactions on Graphics 25(3), 2006, 835-846, the section on finding correspondences (pairwise matches joined into tracks, and the rule that drops a track with two features in one image)
- Johannes L. Schönberger and Jan-Michael Frahm, Structure-from-motion revisited, IEEE Conference on Computer Vision and Pattern Recognition (CVPR 2016), 4104-4113, the correspondence search and the scene graph (tracks as the multiview correspondences of the incremental pipeline)
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 11, Structure from motion and SLAM (feature tracks and their use in multi-frame structure from motion)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag MRQ8VT Edit this page History Report an error Markdown