-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add label background #9018
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
Add label background #9018
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9018
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 670ffa5 with merge base ac7ad5f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @AntoineSimoulin , this looks good! I made some minor comments below, it'd be also great to have some small test to check the expected behavior, similar to the existing tests we have for draw_bounding_boxes
torchvision/utils.py
Outdated
draw.rectangle( | ||
(left - box_margin, top - box_margin, right + box_margin, bottom + box_margin), fill=color | ||
) | ||
label_color = "black" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any reason to force label_color
to black? Could we just make black
the default, but let the user specify it if they wanted to?
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
@NicolasHug, thanks for the comments. I did the following modifications:
|
1d7c355
to
eabb41a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Hey @AntoineSimoulin! You merged this PR, but no labels were added. |
Context
This PR add the ability to add background color for the label of bounding boxes. In this case, the background label will be the same as the one used for the box frame. The text itself will automatically be switched to black. This should allow better visibility in cases where brightness and darkness prevent from distinguishing regular labels, as mentioned in #8317
How to use
We add a
fill_labels
parameter in thedraw_bounding_boxes
function. As illustrated below, this will draw a colored rectangle with the same size of the text rectangle for the text label. By default, the option is deactivated.