Skip to content

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

1 participant