-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
GitHub Issue: ROI Statistics with Out-of-Bounds ROI
Title
Fix ValueError when computing statistics on ROI extending beyond image boundaries
Labels
- bug
- image processing
- ROI
Description
Problem
When computing statistics (or any feature) on an image with a ROI that extends beyond the canvas boundaries, a ValueError is raised:
ValueError: zero-size array to reduction operation minimum which has no identity
Steps to Reproduce
- Create an image (e.g., 100x100 pixels)
- Define a ROI that extends beyond the image canvas (e.g., rectangle at x=80, y=80 with width=30, height=30, extending to x=110, y=110)
- Compute statistics on the image with this ROI
- Error is raised during statistics computation
Root Cause
The ImageObj.get_data() method did not clip ROI bounding box coordinates to image boundaries. When a ROI extended beyond the canvas, the array slice could result in an empty array (zero-size), causing numpy masked array functions to fail.
Solution
Modified ImageObj.get_data() method in sigima/objects/image/object.py to:
- Clip bounding box coordinates to image boundaries using
max(0, ...)andmin(..., shape) - Handle completely out-of-bounds ROIs by returning a fully masked 1x1 array (containing NaN)
- Properly handle partial overlap cases
Test Cases
Three scenarios tested:
- ROI partially extending beyond canvas (right/bottom) - ✅ Works
- ROI completely outside canvas - ✅ Returns NaN values
- ROI with negative coordinates (extends beyond top/left) - ✅ Works
Files Changed
sigima/objects/image/object.py- FixedImageObj.get_data()methodCHANGELOG.md- Documented the fix
Backward Compatibility
This fix maintains backward compatibility. Existing code will continue to work, and ROIs that were previously within bounds behave identically.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working