Skip to content

Add FREAK binary descriptor module #80

Description

@kalwalt

Summary

Add src/freak/freak.ts — the FREAK descriptor (Alahi et al., CVPR 2012),
ported from OpenCV's xfeatures2d, alongside the existing orb binary
descriptor.

Scope narrowed from the original wording: this issue is FREAK and only FREAK.
TEBLID and GMS now have issues of their own.

Motivation

jsfeatNext ships one binary descriptor (orb, ORB/rBRIEF-style). FREAK uses a
retinal sampling pattern with pairwise intensity comparisons and occupies a
niche none of the alternatives cover:

It estimates orientation internally, from 45 long-distance sampling pairs
(NB_ORIENPAIRS), instead of relying on an angle supplied by the detector. That
matters concretely: detectors that produce no orientation (StarDetector/CenSurE
being the obvious candidate for PureCV) work with FREAK out of the box, whereas
pairing them with TEBLID would require a separate orientation estimator such as
the intensity centroid ORB uses.

It also supports cascade matching — the first 16 bytes reject most candidates
before the remaining 48 are compared — which sits naturally on top of a
Hamming brute-force matcher.

Scope

  • Retinal sampling pattern, pairwise intensity comparisons → binary descriptor.
  • Internal orientation estimation from the 45 long-distance pairs.
  • API shaped like orb.describe(...) for consistency.
  • Attached as jsfeatNext.freak.

The design decision this issue must make explicitly

Pattern generation is not a porting detail. OpenCV's buildPattern()
allocates NB_SCALES × NB_ORIENTATION × NB_POINTS = 64 × 256 × 43 = 704,512
PatternPoint structures of 12 bytes each — roughly 8.5 MB on the heap at
construction. That is heavy for WASM and simply impossible for no_std on
constrained targets, which is what the PureCV port faces downstream.

This is not intrinsic to the algorithm, only to OpenCV's implementation, which
trades memory for computation. Three options:

  1. Compute on demand. Pattern points are
    (x·cosθ − y·sinθ, x·sinθ + y·cosθ) scaled; recomputing them per keypoint
    costs a few dozen float operations against 8.5 MB saved. Preferred.
  2. Reduce NB_ORIENTATION from 256 to 32 or 64 → a ~1–2 MB table, with
    negligible loss of angular precision (256 steps is 1.4°, well beyond the real
    accuracy of any orientation estimator).
  3. Lazy per-scale population of only the scale indices the frame's keypoints
    actually use.

Suggested resolution: (1) as the default, (2) available as an option. Whichever
is chosen must be stated in the PR description, because PureCV inherits it — and
if the decision stays implicit, the OpenCV implementation gets ported literally
and the memory profile comes with it.

Acceptance criteria

Non-goals

Dependencies

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions