Skip to content

Add theme_normalize: match a light-mode template in dark mode#445

Merged
JE-Chen merged 1 commit into
devfrom
feat/theme-normalize-batch
Jun 26, 2026
Merged

Add theme_normalize: match a light-mode template in dark mode#445
JE-Chen merged 1 commit into
devfrom
feat/theme-normalize-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Fourth feature of the ROUND-15 perception lane. match_template correlates raw pixel intensities, so a light-mode template scores terribly against the same control in dark mode — the polarity is inverted. The fix is to compare structure (edges, gradients).

  • Headless core utils/theme_normalize/: normalize_theme (map an image to a polarity-invariant single channel — sobel/laplacian gradient magnitude, identical for an image and its colour inverse, or zscore), match_theme (normalize both template and screen, then locate via visual_match.match_template — finds the template across a light/dark flip). cv2/numpy imported lazily so the module/package stays importable without them.
  • 5 layers wired: facade __all__; AC_match_theme executor command; ac_match_theme MCP tool (read-only); Script Builder under Image. normalize_theme (returns an image array) is the Python-API surface.
  • Docs: EN + Zh v217_features_doc.rst + WHATS_NEW.md.

Test

test/unit_test/headless/test_theme_normalize_batch.py — polarity invariance (normalize_theme(img) == normalize_theme(255-img) for sobel), zscore shape/dtype, unknown-method raises, match_theme finds a template embedded inverted in the haystack; wiring + facade tests run cv2-free (lazy import) while behavior tests use per-function importorskip. All green (cv2 present); ruff + bandit + radon clean; no float ==; package stays Qt-free.

match_template correlates raw pixel intensities, so a light-mode template
scores terribly against the same control in dark mode (polarity inverted).
normalize_theme maps an image to a polarity-invariant single channel
(sobel/laplacian gradient magnitude, identical for an image and its
inverse) and match_theme normalizes both sides before locating via
visual_match.match_template. cv2/numpy imported lazily.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 20 complexity · 0 duplication

Metric Results
Complexity 20
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.

@JE-Chen JE-Chen merged commit 2ed02f2 into dev Jun 26, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/theme-normalize-batch branch June 26, 2026 01:31
@sonarqubecloud

Copy link
Copy Markdown

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