Repository navigation
feat: add Histogram.compare with seven comparison methods - #203
Merged
Merged
Conversation
Compares each plane with the same plane of another histogram using OpenCV's six compareHist methods and the earth mover's distance, after normalizing both to sum to one. The method name is case insensitive and can be any unique prefix. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 38 |
| Duplication | 0 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Histogram.compare(other, method="correlation"), which compares each plane of one histogram with the same plane of another and returns a float (one plane) or a list of floats (several planes).compareHistmethods (correlation,chisqr,intersection,bhattacharyya,chisqr_alt,kl_div) and the earth mover's distance (emd).hellingeris accepted as another name forbhattacharyya, which is the same calculation in OpenCV."corr"works. An exact name wins, so"chisqr"is not ambiguous with"chisqr_alt", but"chi"raises aValueErrorthat lists the choices.Histogram.pdffirst, so images of different sizes can be compared.cv2.EMDL1does not exist in OpenCV 5.0, andcv2.EMDneeds signatures, so this is simpler.h1.compare(h2)is not always the same ash2.compare(h1):chisqrandkl_divare asymmetric. The docstring says so and says which methods mean "more similar" with a larger number and which with a smaller one.Histogramraises an exception.Testing
11 new tests in
tests/test_image_whole_features.pycover identical histograms, the EMD of a known 3-bin shift, asymmetry, image-size independence, abbreviations, bad names, color images and mismatches. I broke the code two ways to check they fail (no normalization, and no absolute value in the EMD), and they did.mypypasses with zero errors and all 51 tests in that file pass, on OpenCV 5.0 only. Not run: OpenCV 4, the docs build, and the full suite (left to CI).The docstring has
.. versionadded:: 2.5.0, assuming this ships as the next minor release.This change was written with AI assistance (Claude Code) and the diff has been reviewed by the maintainer.
🤖 Generated with Claude Code