Repository navigation
fix: do not change the template in similarity with a z metric - #237
Merged
Merged
Conversation
similarity(T, "zncc") and "zssd" removed the template's mean with T_im -= np.mean(T_im), which changes the caller's template in place, so a second call used a different template. On a uint8 image or template the same line raised UFuncTypeError, because a float mean cannot be subtracted in place from uint8. The offsets are now removed into new float32 arrays, which also is the type cv2.matchTemplate needs for the result to be meaningful. The two xfail tests that recorded the bugs are now ordinary tests, with a z-SSD test on uint8 images. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 2 |
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
image.similarity(T, "zncc")and"zssd"removed the mean from the template withT_im -= np.mean(T_im), which changes the caller's template in place. Calling it a second time, or using the template for anything else afterwards, used a different template. On auint8image or template the same line raisedUFuncTypeError, because a float mean cannot be subtracted in place from auint8array, so thezmetrics did not work on 8-bit images at all.The offsets of the template and of the image are now removed into new
float32arrays, so nothing the caller owns is changed, and 8-bit images work.Found by the new similarity tests (PR 223), which recorded both as strict
xfailtests. They are now ordinary tests. Azncconuint8images finds the template at its position with a score of 1, leaves the image and the template unchanged, and azssdtest does the same for its minimum.Testing
tests/test_image_spatial_extra.pyandtests/test_image_spatial.py: 120 passed and 2xfail, each of which belongs to a different bug.mypyreports no issues. Not run: CI on Windows or OpenCV 4 (CI will).This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.
🤖 Generated with Claude Code