deeplabcut.pose_estimation_pytorch.data.image
Classes and functions to manipulate images.
Functions:
| Name | Description |
|---|---|
load_image |
Loads an image from a file using cv2. |
resize_and_random_crop |
Resizes images while preserving their aspect ratio. |
top_down_crop |
Crops images around bounding boxes for top-down pose estimation. Computes offsets |
load_image
Loads an image from a file using cv2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
the path of the file containing the image to load |
required |
|
str
|
{'RGB', 'BGR'} the color mode to load the image with |
'RGB'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
the image as a numpy array |
Source code in deeplabcut/pose_estimation_pytorch/data/image.py
resize_and_random_crop
resize_and_random_crop(
image: ndarray,
targets: dict,
size: int | tuple[int, int],
max_size: int | None = None,
max_shift: int | None = None,
) -> tuple[torch.tensor, dict]
Resizes images while preserving their aspect ratio.
resizes to square images.
First, resizes the image so that it's short side is equal to size. If this
makes its long side greater than max_size, resizes the long side to max_size
and the short side to the corresponding value to preserve the aspect ratio.
Then, the image is cropped to a size-by-size square with a random crop.
If size is a tuple, resize images to (w=size[1], h=size[0])
First, rescales the image while preserving the aspect ratio such that both its
width and height are greater or equal to the target width/height for the image
(where either the width/height is the target width/height). If this makes its
long side greater than max_size, resizes the long side to max_size.
Then, the image is cropped to (w=size[1], h=size[0]) with a random crop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
an image of shape (C, H, W) |
required |
|
dict
|
the dictionary containing targets |
required |
|
int | tuple[int, int]
|
the size of the output image (it will be square) |
required |
|
int | None
|
if defined, the maximum size of any side of the output image |
None
|
|
int | None
|
the maximum shift for the crop after resizing |
None
|
image, targets
| Type | Description |
|---|---|
tuple[tensor, dict]
|
the resized image as a PyTorch tensor the updated targets in the resized image |
Source code in deeplabcut/pose_estimation_pytorch/data/image.py
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 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 | |
top_down_crop
top_down_crop(
image: ndarray,
bbox: ndarray,
output_size: tuple[int, int],
margin: int = 0,
center_padding: bool = False,
crop_with_context: bool = True,
) -> tuple[np.array, tuple[int, int], tuple[float, float]]
Crops images around bounding boxes for top-down pose estimation. Computes offsets so that coordinates in the original image can be mapped to the cropped one;
x_cropped = (x - offset_x) / scale_x
x_cropped = (y - offset_y) / scale_y
Bounding boxes are expected to be in COCO-format (xywh).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
(h, w, c) the image to crop |
required |
|
ndarray
|
(4,) the bounding box to crop around |
required |
|
tuple[int, int]
|
the (width, height) of the output cropped image |
required |
|
int
|
a margin to add around the bounding box before cropping |
0
|
|
bool
|
whether to center the image in the padding if any is needed |
False
|
|
bool
|
Whether to keep context around the bounding box when cropping |
True
|
Returns:
| Type | Description |
|---|---|
tuple[array, tuple[int, int], tuple[float, float]]
|
cropped_image, (offset_x, offset_y), (scale_x, scale_y) |
Source code in deeplabcut/pose_estimation_pytorch/data/image.py
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 248 249 250 251 252 253 254 255 256 257 258 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 | |