Skip to content

fix: allow a minimum disparity of zero in stereo_simple - #231

Merged
petercorke merged 3 commits into
mainfrom
bug/stereo-simple-zero-disparity
Nov 22, 2026
Merged

petercorke merged 3 commits into
mainfrom
bug/stereo-simple-zero-disparity

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Image.stereo_simple() failed for any disparity range that starts at zero, such as drange=[0, 12] or (0, 12), with ValueError: operands could not be broadcast together. It shifts the right image with right_arr[:, :-drange[0]], which for a minimum of 0 is right_arr[:, :-0], an empty slice. A minimum of zero is a legitimate range (zero disparity is a point at infinity), and stereo_BM and stereo_SGBM accept it. The slice now uses right_arr.shape[1] - drange[0], which is right for zero as well.

An integer drange, which the code turns into (0, n), failed for the same reason and now works, as it already did in stereo_BM and stereo_SGBM. It was in neither the signature nor the :type: of any of the three methods, so a second commit adds | int to all three and documents that an integer n means (0, n).

Found by the new stereo tests (PR 220), which recorded it as a strict xfail test. That test is replaced by tests of ranges starting at zero: the true disparity of a synthetic pair is recovered with a ZNCC of 1, and the result agrees with a range starting at 4, and an integer gives the same result as [0, n].

Testing

tests/test_image_multiview.py: 19 passed and 1 xfail, which belongs to a separate bug (the size of the outputs). 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

petercorke and others added 2 commits November 22, 2026 21:09
stereo_simple shifted the right image with right_arr[:, :-drange[0]], which for
a minimum disparity of 0 is right_arr[:, :-0], an empty slice, so any range
starting at zero (drange=[0, 12], or an int, which becomes (0, n)) failed with
a broadcast error. The slice now uses the width minus the minimum, which is
right for zero as well.

The xfail test that recorded the bug is replaced by tests of ranges starting at
zero, one of which checks it agrees with a larger minimum.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
stereo_simple, stereo_BM and stereo_SGBM already accept a single integer n for
drange, meaning (0, n), but it was in neither the signature nor the :type:.
Add it to both, say what it means, and test it in stereo_simple.

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 312e12d into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the bug/stereo-simple-zero-disparity branch November 22, 2026 13:16
@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