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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
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
28 29 30 31 32 33 34 35 36 37 38 39 40 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 |
|
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
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 |
|