Skip to content
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

Letterbox of images #505

Closed
1 of 2 tasks
hardikdava opened this issue Oct 19, 2023 · 12 comments
Closed
1 of 2 tasks

Letterbox of images #505

hardikdava opened this issue Oct 19, 2023 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@hardikdava
Copy link
Collaborator

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Description

It would be great to have a feature which resize images as per letterbox concept i.e. resize based on maximum size and adding padding to an image. This is very helpful resize method to increase result quality.

Use case

  • Best method for preprocessing image before detector, segmentation models.

Additional

def letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32) -> np.ndarray:

use case:

import supervision as sv
import cv2

image = cv2.imread(...)
image = sv.letterbox(image)

detection_result = detector(image)

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@hardikdava hardikdava added the enhancement New feature or request label Oct 19, 2023
@SkalskiP
Copy link
Collaborator

Hi @hardikdava 👋🏻 Yup! That's an excellent idea. But then your detection_result is in the context of letterbox so we would need to have a utility capable of reversing this process.

@hardikdava
Copy link
Collaborator Author

Hi @SkalskiP 👋 , you are absolutely correct.

@SkalskiP
Copy link
Collaborator

@hardikdava, what is the meaning of all of those arguments? Is that function definition copied from YOLOv8?

@hardikdava
Copy link
Collaborator Author

@hardikdava, what is the meaning of all of those arguments? Is that function definition copied from YOLOv8?

Yeah, for a quick info. But we can modify them and use only needed.

@SkalskiP
Copy link
Collaborator

We probably should if we don't want licensing issues.

@SkalskiP SkalskiP self-assigned this Nov 15, 2023
@EduardoPach
Copy link

EduardoPach commented Dec 1, 2023

Hey @SkalskiP how are you doing on this? If I'm not mistaken this is the same as used in DETR transformation and we could copy it from the transformers library. Let me know if you have the bandwidth to take care of this issue otherwise I'd love to help out

@SkalskiP
Copy link
Collaborator

SkalskiP commented Apr 8, 2024

This issue was implemented via #1028. sv.letterbox_image will be released in supervision-0.20.0.

@SkalskiP SkalskiP closed this as completed Apr 8, 2024
@hardikdava
Copy link
Collaborator Author

Hello @SkalskiP @LinasKo 👋 , do we have any function which rescale detection to original image after letterbox image?

@LinasKo
Copy link
Contributor

LinasKo commented Dec 3, 2024

Hi @hardikdava 👋

Good to see you in supervision again :)

Unfortunately not. Letterbox resizes the image and then applies letterboxing, so undoing the effect is tricky without knowing the exact params it used. Exposing those would make the API messy.

@hardikdava
Copy link
Collaborator Author

@LinasKo can't we recalculate them based on knowing letterbox_resolution, input_image_resolution?

@LinasKo
Copy link
Contributor

LinasKo commented Dec 3, 2024

My bad, you're right. I thought it was automatic.

I'm very short on time this week, but would be happy to review a PR or implement it when I have a spare minute. Should be a tiny feature.

Would that be something you have time for, or shall I put it on my backlog?

@hardikdava
Copy link
Collaborator Author

@LinasKo I have opened up a PR to support this functionality.

#1708

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

No branches or pull requests

4 participants