Skip to content

fix: replace DSI_refine drange with dmin and ignore NaN planes - #247

Merged
petercorke merged 2 commits into
mainfrom
bug/dsi-refine
Nov 23, 2026
Merged

petercorke merged 2 commits into
mainfrom
bug/dsi-refine

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Fixes the two faults in DSI_refine() from the bug list.

  1. drange was compared with plane indices, and the result was a plane index. For a DSI made by stereo_simple(..., drange=[4, 12]) and a true disparity of 8, the refined values were about 4, and DSI_refine(dsi, (4, 12)) raised IndexError. The DSI does not record its first disparity, so drange is replaced by dmin, the disparity of the first plane (default 0). The result is the plane index plus dmin, minus the sub-pixel offset. DSI_refine(DSI), as in the book, returns what it did before.
  2. np.argmax returns the first NaN. A pixel with a good peak and some NaN planes (disparities that reach beyond the image edge) came out NaN. The peak is now the best valid plane. The result is still NaN where every plane is NaN, where the peak is the first or last plane, where a neighbour is NaN, and where the peak is flat (no warnings in the last two cases).

The docstring explains that the returned disparities are relative to drange[0] of stereo_simple(), and that dmin turns them into true disparities. The function is also no longer a Python loop over pixels. stereo_BM and stereo_SGBM annotations now include int, which they already accepted (meaning (0, n)).

drange is removed from DSI_refine, which is incompatible for anyone who passed it, though it only worked when the range started at 0. It is a plain fix: with .. versionchanged:: 2.5.0.

Tests: exact parabolas with known sub-pixel peaks, dmin, peaks in the first and last plane, NaN planes, an all-NaN fibre, a NaN neighbour and a flat peak without warnings, and the DSI from a real stereo_simple of a shifted pair (true disparity 8, DSI starting at 4, which used to raise). mypy reports no issues and the full suite passes (2118 passed, 33 skipped).

AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.

🤖 Generated with Claude Code

DSI_refine compared drange with plane indices and returned a plane index, so
a DSI that did not start at disparity 0 gave wrong values or an IndexError.
It also used argmax, which returns the first NaN, so a pixel with a good peak
and some NaN planes came out NaN. dmin is the disparity of the first plane;
the default 0 keeps the result of DSI_refine(DSI). stereo_BM and stereo_SGBM
annotations now include int, which they already accepted.

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

Metric Results
Complexity 8
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 56d26b4 into main Nov 23, 2026
32 checks passed
@petercorke
petercorke deleted the bug/dsi-refine branch November 23, 2026 05:53
@github-actions github-actions Bot mentioned this pull request Nov 23, 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