Preprocess
letterbox_image(image, desired_size, color=(0, 0, 0))
¶
Resize and pad image to fit the desired size, preserving its aspect ratio.
Parameters: - image: numpy array representing the image. - desired_size: tuple (width, height) representing the target dimensions. - color: tuple (B, G, R) representing the color to pad with.
Returns: - letterboxed image.
Source code in inference/core/utils/preprocess.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
prepare(image, preproc, disable_preproc_contrast=False, disable_preproc_grayscale=False, disable_preproc_static_crop=False)
¶
Prepares an image by applying a series of preprocessing steps defined in the preproc
dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
The input PIL image object. |
required |
preproc
|
dict
|
Dictionary containing preprocessing steps. Example: { "resize": {"enabled": true, "width": 416, "height": 416, "format": "Stretch to"}, "static-crop": {"y_min": 25, "x_max": 75, "y_max": 75, "enabled": true, "x_min": 25}, "auto-orient": {"enabled": true}, "grayscale": {"enabled": true}, "contrast": {"enabled": true, "type": "Adaptive Equalization"} } |
required |
disable_preproc_contrast
|
bool
|
If true, the contrast preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_grayscale
|
bool
|
If true, the grayscale preprocessing step is disabled for this call. Default is False. |
False
|
disable_preproc_static_crop
|
bool
|
If true, the static crop preprocessing step is disabled for this call. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
ndarray
|
PIL.Image.Image: The preprocessed image object. |
|
tuple |
Tuple[int, int]
|
The dimensions of the image. |
Note
The function uses global flags like DISABLE_PREPROC_AUTO_ORIENT
, DISABLE_PREPROC_STATIC_CROP
, etc.
to conditionally enable or disable certain preprocessing steps.
Source code in inference/core/utils/preprocess.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
resize_image_keeping_aspect_ratio(image, desired_size)
¶
Resize reserving its aspect ratio.
Parameters: - image: numpy array representing the image. - desired_size: tuple (width, height) representing the target dimensions.
Source code in inference/core/utils/preprocess.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|