Repository navigation
fix: esttheta() -- broken pickregion() helper and missing theta-sweep body - #82
Merged
Merged
Conversation
… body
Multiple compounding bugs in esttheta()/pickregion(), all part of the
same incomplete migration/port:
- pickregion() called smb.plot_poly() (removed from spatialmath-python)
immediately before an already-migrated replacement two lines later
(Polygon2(...).plot(...)) that draws the identical thing -- delete
the redundant broken leftover rather than fix it.
- The "already-migrated" replacement was itself broken: smb.Polygon2
doesn't exist (Polygon2 lives in top-level spatialmath, not
spatialmath.base) -- add the import, matching every other call site
in the codebase (ImageConstants.py, Sources.py, ImageBlobs.py,
ImageCore.py, tagtool.py all do `from spatialmath import Polygon2`).
- polygon.plot("g") passed "g" positionally, binding to Polygon2.plot's
ax parameter (not color) -- a leftover calling convention from the
old plot_poly(xy, "g", close=True) API. Fixed to polygon.plot(color="g").
- esttheta()'s body never computed or returned theta at all -- only the
interactive region-picking half of the original MATLAB function
(toolbox/esttheta.m) was ported; the theta-sweep/variance-minimization
loop was entirely missing, so the function always implicitly returned
None despite its own docstring promising a float. Implemented the
sweep using the already-ported shadow_invariant() (MVTB's existing
Python port of MATLAB's invariant()/shadowRemoval()), matching the
original: sweep theta in [0, pi), compute the invariant image at each
candidate angle, minimize std() over non-inf/nan pixels, return the
best angle. Added a marker at the minimum and grid to the diagnostic
plot.
- im.column() -> im.view1d(): column() is already deprecated.
- pickregion() now calls h.figure.ginput(...) on the actual Figure
handle returned by im.disp(), instead of the module-level
plt.ginput() (which resolves its target through gcf()'s implicit
global state). More robust regardless of backend.
Root-caused while working through RVC3-python's chap10.ipynb notebook
test suite. Note: ginput()'s click events are not reliably delivered
under %matplotlib widget (ipympl) in Jupyter -- this is a known,
long-standing upstream ipympl limitation (ipympl#400), not something
fixable here; documented in the notebook as needing %matplotlib tk/qt
for that cell.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
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
Multiple compounding bugs in
esttheta()/pickregion(), all part of the same incomplete migration/port, found while root-causing RVC3-python's chap10.ipynb notebook test suite:pickregion()calledsmb.plot_poly()(removed from spatialmath-python) immediately before an already-migrated replacement two lines later (Polygon2(...).plot(...)) that draws the identical thing -- deleted the redundant broken leftover.smb.Polygon2doesn't exist (Polygon2lives in top-levelspatialmath, notspatialmath.base) -- added the import, matching every other call site in the codebase (ImageConstants.py,Sources.py,ImageBlobs.py,ImageCore.py,tagtool.pyall dofrom spatialmath import Polygon2).polygon.plot("g")passed"g"positionally, binding toPolygon2.plot'saxparameter (not color) -- a leftover calling convention from the oldplot_poly(xy, "g", close=True)API. Fixed topolygon.plot(color="g").esttheta()'s body never computed or returned theta at all -- only the interactive region-picking half of the original MATLAB function (toolbox/esttheta.m) was ported; the theta-sweep/variance-minimization loop was entirely missing, so the function always implicitly returnedNonedespite its own docstring promising afloat. Implemented the sweep using the already-portedshadow_invariant()(MVTB's existing Python port of MATLAB'sinvariant()/shadowRemoval()), matching the original algorithm: sweep theta in[0, pi), compute the invariant image at each candidate angle, minimizestd()over non-inf/nan pixels, return the best angle. Added a marker at the minimum and a grid to the diagnostic plot.im.column()->im.view1d():column()is already deprecated.pickregion()now callsh.figure.ginput(...)on the actualFigurehandle returned byim.disp(), instead of the module-levelplt.ginput()(which resolves its target throughgcf()'s implicit global state). More robust regardless of backend.Note:
ginput()'s click events are not reliably delivered under%matplotlib widget(ipympl) in Jupyter -- this is a known, long-standing upstream ipympl limitation (ipympl#400), not something fixable here. Documented in the RVC3-python notebook as needing%matplotlib tk/qtfor that specific cell.Test plan
tests/base/test_base_color.py,tests/test_image_color.py) pass, no regressionsrvctooland Jupyter against the realparks.pngimage (region picking, plotting,h.figure.ginput()fix)