Skip to content

Add fixed-pixel ROI padding, complementing bbox_expansion - #419

Open
animmosmith wants to merge 1 commit into
415-416-pipeline-progress-logging-and-print-steps-fixfrom
418-fixed-pixel-roi-padding
Open

Add fixed-pixel ROI padding, complementing bbox_expansion#419
animmosmith wants to merge 1 commit into
415-416-pipeline-progress-logging-and-print-steps-fixfrom
418-fixed-pixel-roi-padding

Conversation

@animmosmith

Copy link
Copy Markdown
Collaborator

Summary

Closes #418.

bbox_expansion already lets a particle's bounding box be expanded before its ROI is cropped, but that expansion is fractional - it scales with each particle's own size. There was no way to add a fixed, consistent pixel margin regardless of particle size - e.g. to guarantee a small non-particle border around every ROI fed to the classifier (which runs on this same cropped ROI as the exported file), or for visual inspection/montage context.

Adds a new pad_bbox() helper (fixed-pixel analogue of the existing expand_bbox()) and a pad parameter threaded through the same chain bbox_expansion already uses: extract_roi -> extract_particles -> statextract -> CalculateStats. pad is applied on top of bbox_expansion, so either, both, or neither can be used. Clamped to image bounds the same way.

Version bumped to 2.16.23, ready to merge once the rest of the current chain is in.

Test plan

  • flake8 pyopia clean.
  • Fast test subset (pytest -m "not slow and not training"): 36 passed.
  • Manually verified: pad=0 matches prior behaviour exactly, pad alone and combined with bbox_expansion both produce the expected crop sizes, edge-clamping behaves correctly (verified against real particles near a raw image's top edge), and negative pad raises ValueError.
  • Verified end-to-end with real SilCam data through the full CLI: same particles' exported ROIs are measurably larger with pad=10 configured vs. without, confirming the parameter reaches the classifier and export path correctly, not just the isolated helper functions.

🤖 Generated with Claude Code

Closes #418.

bbox_expansion already lets a particle's bounding box be expanded before its
ROI is cropped, but that expansion is fractional - it scales with each
particle's own size. There was no way to add a fixed, consistent pixel
margin regardless of particle size, e.g. to guarantee a small non-particle
border around every ROI fed to the classifier (which is run on this same
cropped ROI as the exported file), or for visual inspection/montage context.

Adds a new pad_bbox() helper (fixed-pixel analogue of the existing
expand_bbox()) and a pad parameter threaded through the same chain
bbox_expansion already uses: extract_roi -> extract_particles -> statextract
-> CalculateStats. pad is applied on top of bbox_expansion, so either, both,
or neither can be used. Clamped to image bounds the same way.
@animmosmith animmosmith self-assigned this Aug 5, 2026
@animmosmith animmosmith added patch / enhancement improved functionality or patch indented for changes that require bumping only the PATCH number priority-low labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch / enhancement improved functionality or patch indented for changes that require bumping only the PATCH number priority-low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fixed-pixel ROI padding, complementing bbox_expansion

1 participant