Skip to content

Make RLE or Masks from Bounding Boxes #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ahmed-G-ElTaher
Copy link

@Ahmed-G-ElTaher Ahmed-G-ElTaher commented May 9, 2025

Direct Conversion from Bounding Boxes to RLE/Masks

This PR adds functionality to directly convert bounding boxes to RLE format or binary masks without requiring segmentation data.

Implementation

The enhancement modifies the annToRLE method in coco.py to:

  • Check if a bbox field exists when no segmentation field is provided
  • Use bounding box coordinates to create an RLE representation of the rectangular region
  • Maintain backward compatibility with original functionality

This allows the existing annToMask method to work with bounding box annotations automatically, as it relies on annToRLE for the conversion process.

Benefits

  • Simplifies workflow: No need to manually convert bounding boxes to masks
  • Works with existing COCO API methods that use RLE or masks
  • Original functionality is unaffected
  • Provides a standardized way to convert from bounding boxes to masks

Testing

Tested with:

  • Annotations containing only bounding boxes
  • Mixed datasets with both segmentation and bbox-only annotations
  • Various COCO API operations that require masks

@Ahmed-G-ElTaher
Copy link
Author

@tylin
Can you check this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant