supervision icon indicating copy to clipboard operation
supervision copied to clipboard

Letterbox of images

Open hardikdava opened this issue 2 years ago • 6 comments
trafficstars

Search before asking

  • [X] 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 avatar Oct 19 '23 10:10 hardikdava

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.

SkalskiP avatar Oct 19 '23 13:10 SkalskiP

Hi @SkalskiP 👋 , you are absolutely correct.

hardikdava avatar Oct 19 '23 14:10 hardikdava

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

SkalskiP avatar Oct 19 '23 14:10 SkalskiP

@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.

hardikdava avatar Oct 19 '23 14:10 hardikdava

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

SkalskiP avatar Oct 19 '23 15:10 SkalskiP

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

EduardoPach avatar Dec 01 '23 19:12 EduardoPach

This issue was implemented via https://github.com/roboflow/supervision/pull/1028. sv.letterbox_image will be released in supervision-0.20.0.

SkalskiP avatar Apr 08 '24 12:04 SkalskiP