Fix empty mask overlay handling when no objects are detected. #350
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.
Context
In the current implementation, when no object instances are found in the image, the function simply prints "No objects found in the image." and returns early, potentially leaving users without a usable output for downstream processing.
Proposed Changes
Empty Mask Overlay Creation: I added a line to create and return an empty mask overlay in cases where no objects are detected. This ensures that users still receive a consistent output type, even when no detections occur.
if boxes is None or (len(boxes) == 0): # No "object" instances found print("No objects found in the image.") mask_overlay = np.zeros_like(image_np[..., 0], dtype=dtype)
This change allows for easier downstream processing and integration, providing users with a consistent output type regardless of the detection results.
Related Issue
This addresses issue #348