Repository navigation
fix: make stereo_simple return outputs the size of its inputs - #240
Merged
Merged
Conversation
The window stack is 2*hw larger than the image in each direction, and the outputs kept that padding, against the docstring. Crop the stack to the windows centred on the image's pixels, so the disparity, similarity and disparity space images are the size of the inputs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An integer image was padded with NaN, which numpy casts to 0, so windows beyond the image were treated as valid zero padding, and a float image gave a different result. Convert to float32 first. A NaN similarity at one disparity also made the whole pixel NaN, because np.max propagates NaN, so take the best of the valid disparities and give NaN only to a pixel with none. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add a note on the width of the NaN band in the disparity, similarity and DSI images, remove the now redundant assignment of the left columns, and test the band on every side and in each plane of the DSI. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 4 |
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.stereo_simple()had three faults that all come from how it builds its stack of windows.2*hwin each direction, although the docstring says they are the same size, and the result for pixel (u, v) was at (u+hw, v+hw). The window stack is now cropped to the windows centred on the image's pixels. The existing strictxfailtest recorded this.RuntimeWarning), so windows that extend beyond the image were treated as valid zero padding, and auint8image gave different results from the same image asfloat32. The images are now converted tofloat32first, so the padding is a real NaN for every image type.np.argmaxandnp.max, so a single NaN similarity at one disparity made the whole pixel NaN, even where other disparities were valid. A pixel now takes the best of its valid disparities, and is NaN only if none is valid.Behaviour change
Outputs are the size of the inputs. A band of
hwNaN pixels runs along the top, bottom and right edges, and the left band ishw + drange[0]wide (in each plane of the DSI,hw + drange[0] + d). The redundantdisparity[:, :drange[0]] = nanline is removed, since those columns are already NaN. In the interior, values are identical to before. I compared the old and new output on a random 30x40uint8pair: where both gave a number the disparity, similarity and DSI values were identical.Windows that extend beyond the left edge of a
uint8image used to be matched against zero padding, and now give NaN. This is a visible change foruint8images. For any image type, a pixel near the left edge that has some valid disparities used to be NaN and now has a disparity (change 3).A
.. note::in the docstring describes the NaN bands, and.. versionchanged:: 2.5.0describes the change.Tests
The strict
xfailtest is now an ordinary test. New tests cover the NaN band on all four sides and in each DSI plane,uint8andfloat32giving the same result with warnings turned into errors, a pixel keeping its valid disparities, and a pixel with none being NaN.tests/test_image_multiview.pypasses (25 tests) and mypy reports no errors. I have not run the full suite locally. CI will.DSI_refine()has related faults (it usesnp.argmaxon a DSI that can contain NaN, and it treatsdrangeas plane indices). They are not changed here.This change was written with AI assistance (Claude Code) and I have reviewed the diff.
🤖 Generated with Claude Code