Skip to content

fix: keep the type of the result of blend - #238

Merged
petercorke merged 2 commits into
mainfrom
bug/blend-float64
Nov 22, 2026
Merged

petercorke merged 2 commits into
mainfrom
bug/blend-float64

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Image.blend() built its result with Image(out), which narrows a float64 array to float32 (and a uint16 array whose values fit to uint8) unless a dtype is given. So blending float64 images, or asking for dtype="double" or "float64", gave a float32 image, and blending uint16 images could give uint8. The dtype argument for double precision never worked. It now passes dtype=out.dtype, so the result has the type OpenCV computed.

Found by the new blend tests (PR 223), which recorded the float64 case as a strict xfail test. That test is now an ordinary test. Two more tests cover float64 inputs with the default dtype, and uint16 images, which come back as uint16. Without the change four of the new tests fail.

Testing

tests/test_image_processing_extra.py and tests/test_image_processing.py: 143 passed. mypy reports 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

blend() built its result with Image(out), which narrows a float64 array to
float32 and a uint16 array whose values fit to uint8. So blending float64 images,
or asking for dtype="double", gave float32, and blending uint16 images could give
uint8. It now passes dtype=out.dtype, so the result has the type OpenCV
computed.

The xfail test that recorded the bug is now an ordinary test, with tests for
float64 inputs and uint16 images.

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 0 complexity · 0 duplication

Metric Results
Complexity 0
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 fa85a7c into main Nov 22, 2026
32 checks passed
@petercorke
petercorke deleted the bug/blend-float64 branch November 22, 2026 21:45
@github-actions github-actions Bot mentioned this pull request Nov 22, 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