fix: use P-axis length for ys calculation and clip S-axis bounds (#167)#180
Open
rtmalikian wants to merge 1 commit into
Open
fix: use P-axis length for ys calculation and clip S-axis bounds (#167)#180rtmalikian wants to merge 1 commit into
rtmalikian wants to merge 1 commit into
Conversation
Fixes part 2 of BrainLesion#167: - Use mask_RPS.shape[1] (P-axis) instead of shape[2] (S-axis) for ys calculation, since the defacing line iterates over P positions and computes S-axis limits for each. - Clip y values to mask_RPS.shape[2] to prevent IndexError when the defacing line extends beyond the S-axis range. Previously, using shape[2] for the arrange caused the defacing loop to iterate over S-axis positions instead of P-axis positions, which produced incorrect defacing masks for images with narrow S axes. The old code also lacked bounds clipping, causing IndexError when computed S-axis limits exceeded the array dimensions.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an indexing bug in the QuickShear defacing implementation by computing the defacing-plane ys values across the correct axis (P-axis) and clipping S-axis slice bounds to prevent out-of-range writes.
Changes:
- Compute
ysusingmask_RPS.shape[1](P-axis length) instead ofmask_RPS.shape[2](S-axis length). - Clip computed S-axis limits (
y) tomask_RPS.shape[2]before slicing to avoid out-of-bounds access.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
@uturkbey @nicmuenster do you have time to look into this? |
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
Fixes the second part of #167: incorrect
ysaxis calculation and missing bounds clipping in QuickShear defacing.Root Cause
The
yscalculation inrun_quickshear()usedmask_RPS.shape[2](S-axis length) instead ofmask_RPS.shape[1](P-axis length):In RPS orientation, the defacing loop iterates over P-axis positions (axis 1) and computes S-axis limits (axis 2) for each. Using
shape[2]caused:(666, 512, 30)) — the loop only iterated over 30 positions instead of 512shape[2]bounds (defaced_mask_RPS[:, x, :y]wherey > shape[2])Fix
Verification
Tested with 4 scenarios including the exact shapes from the bug report:
shape[2]=5) ✓512 × 180) — the IndexError case ✓All tests pass with no IndexError and correct defacing behavior.
About the Author: Raphael Malikian — Clinical AI Solutions Architect. I specialise in building and fixing AI/ML systems for healthcare, including vector databases, RAG pipelines, and clinical NLP. If you need help with your project or think I can add value to your organisation, feel free to reach out — I'd love to connect.
📧 rtmalikian@gmail.com
🔗 GitHub: https://github.com/rtmalikian
🔗 LinkedIn: http://www.linkedin.com/in/raphael-t-malikian-mbbs-bsc-hons-71075436a
Disclosure: This code was developed with assistance from mimo-2.5-pro (Xiaomi) via Hermes Agent (Nous Research). All changes were reviewed, tested against the actual codebase, and verified for correctness.