Skip to content

feat: scale, orientation and strength raise for features that do not have them - #275

Merged
petercorke merged 1 commit into
mainfrom
feat/feature-properties-raise
Nov 24, 2026
Merged

petercorke merged 1 commit into
mainfrom
feat/feature-properties-raise

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Makes scale, orientation and strength of a feature set raise ValueError when the features do not have that quantity, and corrects which algorithms say they have what. It is the first step of the work on ComboFeature (item 19 of the bug list), where a detector and a descriptor are combined and the result has only what they provide.

The problem. The properties returned the keypoint's size, angle and response whatever the detector did. For a detector that sets none of them the value is a constant: Harris features reported a scale of 0 and an orientation of 0. The _has_scale and _has_orient flags only decided what print and plot showed, and they were wrong. I compared each algorithm's flags with the keypoints it returns:

algorithm scale and orientation in the data flags before
SIFT real (sizes 1.8 to 246, angles 0 to 360) on
ORB real (31 to 111) off
BRISK real (8 to 72) off
AKAZE real (4.8 to 46) off
Harris none (all 0) off

The change.

  • A third flag, strength, next to the other two (default on, as every detector gives a response).
  • scale, orientation and strength raise ValueError ("FAST features have no scale") if the flag is off. plot(filled=True) needs a scale and plot(hand=True) an orientation, so those raise the same way; a plain plot() needs neither. sort("scale") and filter(minscale=...) raise for a set with no scale.
  • ORB, BRISK and AKAZE are now flagged as having a scale and an orientation. Visible effect: print, table() and list() of those features now show them, and plot(filled=True, hand=True) works on them.
  • A new _like() helper makes a new set with the flags, the feature type and the image copied, and slicing, + and sort(inplace=False) use it. Before, + and sort forgot the flags and the image (sift[:50] + sift[50:100] lost its scale and orientation), and a slice forgot the image.
  • The orientation was printed as radians with a degree sign (a 30 degree feature showed orient=0.5°). It is now printed in degrees. The test that pinned the old output is corrected.
  • .. versionchanged:: 2.5.0 on the three properties.

Not changed here, found while doing this: gridify() returns a set whose keypoints are feature sets, and Harris(scale=15) has no effect on the detector, because its scale option is swallowed by the flag of the same name. Each will be its own PR.

Tests. The flags are checked against the keypoints of the real algorithms (SIFT, ORB, BRISK, AKAZE, Harris): where a flag is on the values must vary, where it is off they must be constant and the property must raise. Also: raising for each property and for a single feature, drawing needing a scale or an orientation, the flags and image kept by slicing, adding, sorting and subsetting, and the printing. 21 of the new tests fail on the old code. mypy reports no issues and the full suite passes (2325 passed, 30 skipped). The chapter 12 notebook uses .strength on Harris and .scale on SIFT, which both still work.

AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.

🤖 Generated with Claude Code

…have them

They returned the keypoint size, angle and response whether or not the detector
sets them, so Harris features reported an orientation of 0 and a scale of 0.
Add a strength flag beside the scale and orientation flags, raise ValueError when
a flag is off, and correct the flags: ORB, BRISK and AKAZE do have a scale and
an orientation. Slicing, adding and sorting now keep the flags and the image,
and the orientation is printed in degrees, not radians with a degree sign.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 37 complexity · 0 duplication

Metric Results
Complexity 37
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit dbe8b4a into main Nov 24, 2026
34 checks passed
@petercorke
petercorke deleted the feat/feature-properties-raise branch November 24, 2026 01:49
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant