image_operations¶
feat.utils.image_operations
¶
py-feat utility and helper functions for performing operations on images.
BBox
¶
Bases: object
Source code in feat/utils/image_operations.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
__add__(bbox2)
¶
Create a new BBox based on the intersection between two BBox instances (OR Operation)
Source code in feat/utils/image_operations.py
__init__(bbox, order=None, left_boundary=0, top_boundary=0, right_boundary=None, bottom_boundary=None)
¶
Class to work with Bounding Box
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
(list): values |
required | |
order
|
list
|
order of values (e.g., ['left', 'top', 'right', 'bottom']) |
None
|
left optional
|
float
|
boundary of left (default 0) |
required |
right toptional
|
float
|
boundary of right border (e.g., width of image) |
required |
top optional
|
float
|
boundary of top border (default 0) |
required |
bottom optional
|
float
|
boundary of right border (e.g., height of image) |
required |
Source code in feat/utils/image_operations.py
__mul__(bbox2)
¶
Create a new BBox based on the intersection between two BBox instances (AND operation)
Source code in feat/utils/image_operations.py
area()
¶
expand_by_factor(factor, symmetric=True)
¶
Expand box by factor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
float
|
factor to expand. |
required |
symmetric
|
bool
|
if symmetric then expand equally based on largest side |
True
|
Source code in feat/utils/image_operations.py
extract_from_image(img)
¶
Crop Image using Bounding Box
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
(array, tensor)
|
image (B, C, H, W) or (C, H, W) or (H,W) |
required |
Returns:
| Type | Description |
|---|---|
|
cropped (np.array, torch.tensor) |
Source code in feat/utils/image_operations.py
inverse_transform_landmark(landmark)
¶
Re-scale landmarks from unit scaling back into BBox
based on https://github.com/cunjian/pytorch_face_landmark/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
(np.array): landmarks |
required |
Returns:
| Type | Description |
|---|---|
|
re-scaled landmarks |
Source code in feat/utils/image_operations.py
overlap(bbox2)
¶
Compute the percent overlap between BBox with another BBox
Source code in feat/utils/image_operations.py
plot(ax=None, fill=False, linewidth=2, **kwargs)
¶
Plot bounding box
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
matplotlib axis |
None
|
|
fill
|
bool
|
fill rectangle |
False
|
Source code in feat/utils/image_operations.py
set_boundary(left=0, right=None, top=0, bottom=None, apply_boundary=True)
¶
Set maximum boundary of bounding box such as the edge of the original image
Use _apply_boundary() method to update the bounding box
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
float
|
boundary of left (default 0) |
0
|
right
|
float
|
boundary of right border (e.g., width of image) |
None
|
top
|
float
|
boundary of top border (default 0) |
0
|
bottom
|
float
|
boundary of right border (e.g., height of image) |
None
|
apply
|
bool
|
apply boundary to BBox |
required |
Source code in feat/utils/image_operations.py
to_dict()
¶
to_list()
¶
transform_landmark(landmark)
¶
Scale Landmarks to be within a 1 unit box (e.g., [0,1])
based on https://github.com/cunjian/pytorch_face_landmark/
Args:
Returns:
| Type | Description |
|---|---|
|
scaled landmarks |
Source code in feat/utils/image_operations.py
HOGLayer
¶
Bases: Module
Source code in feat/utils/image_operations.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
__init__(orientations=10, pixels_per_cell=8, cells_per_block=2, transform_sqrt=False, block_normalization='L2', feature_vector=True, device='auto')
¶
PyTorch HOG feature extractor matching skimage.feature.hog output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orientations
|
int
|
Number of orientation bins. |
10
|
pixels_per_cell
|
int
|
Size in pixels of a square cell. skimage's
|
8
|
cells_per_block
|
int
|
Block side length in cells (square blocks). |
2
|
transform_sqrt
|
bool
|
Apply power-law compression (per-channel
|
False
|
block_normalization
|
str
|
One of |
'L2'
|
feature_vector
|
bool
|
If True, flatten the output in skimage's
|
True
|
device
|
str
|
one of |
'auto'
|
Source code in feat/utils/image_operations.py
plot()
¶
Visualize the hog feature representation. Creates numpy matrix for each image.
Based on skimage.feature._hog
Source code in feat/utils/image_operations.py
align_face(img, landmarks, landmark_type=68, box_enlarge=2.5, img_size=112)
¶
Performs affine transformation to align the images by eyes.
Performs affine alignment based on eyes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
gray or RGB |
required | |
landmark_type
|
int
|
Landmark system (68, 49) |
68
|
landmarks
|
68 system flattened landmarks, shape:(136) |
required | |
box_enlarge
|
relative size of face on the image. Smaller value indicate larger proportion |
2.5
|
Returns:
| Name | Type | Description |
|---|---|---|
aligned_img |
aligned image |
|
new_landmarks |
aligned landmarks |
Source code in feat/utils/image_operations.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
compute_original_image_size(batch_data)
¶
Computes the original image size before padding and scaling for a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_data
|
dict
|
batch_data from data loader containing 'Image', 'Padding', and 'Scale' tensors. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
original_height_width |
Tensor
|
A tensor of shape [batch_size, 2] representing the original heights and widths of the images. |
Source code in feat/utils/image_operations.py
convert68to49(landmarks)
¶
Convert landmark from 68 to 49 points
Function modified from https://github.com/D-X-Y/landmark-detection/blob/7bc7a5dbdbda314653124a4596f3feaf071e8589/SAN/lib/datasets/dataset_utils.py#L169 to fit pytorch tensors. Converts 68 point landmarks to 49 point landmarks
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
landmark points of shape (2,68) |
required |
Return
converted landmarks: converted 49 landmark points of shape (2,49)
Source code in feat/utils/image_operations.py
convert_bbox_output(boxes, scores)
¶
Convert im2pose_output into Fex Format
Source code in feat/utils/image_operations.py
convert_color_vector_to_tensor(vector)
¶
convert_image_to_tensor(img, img_type=None)
¶
Convert Image data (PIL, cv2, TV) to Tensor
Source code in feat/utils/image_operations.py
convert_to_euler(rotvec, is_rotvec=True)
¶
Converts the rotation vector or matrix (the standard output for head pose models) into euler angles in the form of a ([pitch, roll, yaw]) vector. Adapted from https://github.com/vitoralbiero/img2pose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotvec
|
The rotation vector produced by the headpose model |
required | |
is_rotvec
|
|
True
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: euler angles ([pitch, roll, yaw]) |
Source code in feat/utils/image_operations.py
decode(loc, priors, variances)
¶
Decode locations from predictions using priors to undo the encoding we did for offset regression at train time.
Adapted from https://github.com/Hakuyume/chainer-ssd
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
tensor
|
location predictions for loc layers, Shape: [num_priors,4] |
required |
priors
|
tensor
|
Prior boxes in center-offset form. Shape: [num_priors,4]. |
required |
variances
|
(list[float]) Variances of priorboxes |
required |
Return
decoded bounding box predictions
Source code in feat/utils/image_operations.py
expand_img_dimensions(img)
¶
Expand image dimensions to 4 dimensions
Source code in feat/utils/image_operations.py
extract_face_from_bbox(frame, detected_faces, face_size=112, expand_bbox=1.2)
¶
Extract face from image and resize
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
tensor
|
img with faces |
required |
detected_faces
|
list
|
list of lists of face bounding boxes from detect_face() |
required |
face_size
|
int
|
output size to resize face after cropping |
112
|
expand_bbox
|
float
|
amount to expand bbox before cropping |
1.2
|
Returns:
| Name | Type | Description |
|---|---|---|
cropped_face |
Tensor
|
Tensor of extracted faces of shape=face_size |
new_bbox |
list
|
list of new bounding boxes that correspond to cropped face |
Source code in feat/utils/image_operations.py
extract_face_from_bbox_torch(frame, detected_faces, face_size=112, expand_bbox=1.2, frame_idx=None)
¶
Extract face from image and resize using pytorch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
|
required | |
detected_faces
|
|
required | |
face_size
|
output spatial size; crops are returned at
|
112
|
|
expand_bbox
|
multiplier on bbox width/height before clipping to the source frame; lets the crop carry context around the face. |
1.2
|
|
frame_idx
|
optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
cropped_faces |
|
|
new_bboxes |
|
Source code in feat/utils/image_operations.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 | |
extract_face_from_landmarks(frame, landmarks, face_size=112)
¶
Extract a face from a frame using a convex hull around its landmarks.
Aligns the face by 68-landmark transform, masks pixels outside the convex hull of the landmarks, and returns the cropped face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
Tensor
|
image tensor of shape |
required |
landmarks
|
Tensor
|
68 landmark coordinates as a flat or
|
required |
face_size
|
int
|
output crop size in pixels (default 112). |
112
|
Returns:
| Name | Type | Description |
|---|---|---|
masked_image |
aligned cropped face with non-face pixels masked out. |
|
new_landmarks |
landmark coordinates in the aligned crop's frame. |
Source code in feat/utils/image_operations.py
extract_face_square_pad_torch(frame, detected_faces, face_size=256, expand_bbox=1.2, frame_idx=None)
¶
Isotropic square-pad face crop (Detectorv2 / v2.5 training).
Forked from extract_face_from_bbox_torch (which v1 Detector and
MPDetector still use). That one resizes a rectangular box into a square
chip with independent x/y scales โ it stretches the face, erasing the
vertical foreshortening the v2 model needs to infer 3D pose / mesh-depth.
This version instead
- squares the expanded box to its longer side (single scale, no stretch),
- resizes isotropically to
face_size, - reflect-pads any region that falls outside the source frame (the square is NOT clamped to the frame โ off-frame pixels are reflected, so the face stays centred and correctly scaled even at frame edges).
The crop is a single isotropic affine, so mesh/landmark/pose targets map back
to frame coords with one transform and the mesh z-axis stays consistent with
x/y. A normalised chip coord (u, v) in [0, 1] maps to the source frame as
(origin_x + u * side, origin_y + v * side).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
|
required | |
detected_faces
|
|
required | |
face_size
|
output spatial size (square). |
256
|
|
expand_bbox
|
margin multiplier applied before squaring. |
1.2
|
|
frame_idx
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
cropped_faces |
|
|
crop_affine |
|
Source code in feat/utils/image_operations.py
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
extract_hog_features(extracted_faces, landmarks, hog_layer=None)
¶
Extract HOG features for AU classification using torch-native HOGLayer.
Replaces the prior per-face skimage call which round-tripped each face through tensor -> PIL -> numpy -> CPU HOG -> numpy. HOGLayer keeps the whole batch on the input device and matches skimage.feature.hog to ~5e-8 absolute tolerance (verified by test_HOGLayer_matches_skimage); the trained AU classifier needs no retraining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extracted_faces
|
[N, C, H, W] face crops, float32 in [0, 1]. |
required | |
landmarks
|
[N, n_landmarks*2] flattened (x, y) landmark coordinates in image space. |
required | |
hog_layer
|
optional pre-built HOGLayer to reuse across calls. Detectorv1 and MPDetector cache one in init so repeated detect() calls don't pay the per-call construction cost. If None, a fresh layer is built (backward-compat for direct external callers). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
hog_features |
numpy array of shape [N, n_features]. |
|
au_new_landmarks |
list of per-face landmark arrays in the face-aligned crop's coordinates. |
Source code in feat/utils/image_operations.py
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 | |
inverse_transform_landmarks_torch(landmarks, boxes)
¶
Transforms landmarks based on new bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
Tensor
|
Tensor of shape (N, 136) representing 68 landmarks for N samples. |
required |
boxes
|
Tensor
|
Tensor of shape (N, 4) representing bounding boxes [x1, y1, x2, y2] for N samples. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Transformed landmarks of shape (N, 136). |
Source code in feat/utils/image_operations.py
invert_padding_to_results(batch_results, batch_data, n_landmarks)
¶
Vectorized inversion of dataloader padding/scaling on a batch of detector outputs.
Replaces a per-frame loop that previously called compute_original_image_size,
extracted Padding and Scale numpy arrays, and rewrote
FrameHeight, FrameWidth, the four FaceRect* columns, and
x_i / y_i for every landmark inside the loop. The pandas
.loc[mask, col] rewrites scaled quadratically with batch size and
landmark count.
The replacement still does O(rows ร landmarks) work overall (you
have to read and write every cell), but as a constant number of
vectorized numpy ops instead of n_frames ร 2 ร n_landmarks
boolean-mask-then-write pandas operations. For a 60-frame batch
with 478 landmarks the prior loop did ~57k mask writes; the new
helper does 7 column assignments. By steps:
- Mapping each row's
framevalue to its position in the batch. - Looking up per-row
pad_left,pad_top,scale,frame_height,frame_widthonce. - Doing all column updates with broadcasted numpy ops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_results
|
pandas DataFrame (or Fex). Modified in place. |
required | |
batch_data
|
dict from the DataLoader for the current batch with
|
required | |
n_landmarks
|
number of (x_i, y_i) landmark pairs to invert (68 for img2pose / mobilefacenet pipelines, 478 for MediaPipe). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
batch_results |
the same object passed in (returned for chaining). |
Source code in feat/utils/image_operations.py
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 | |
mask_image(img, mask)
¶
Apply numpy mask of (h,w) to pytorch image (b,c,h,w)
Source code in feat/utils/image_operations.py
per_face_padding_inversion_terms(batch_data, frame_idx, device)
¶
Look up per-face DataLoader-Rescale inversion terms.
The DataLoader's Rescale transform pads + scales each frame to a
uniform shape so the batch can collate. forward() consumes the
padded frames directly, so any coordinates it produces (face bboxes,
landmarks) are in padded-frame space. To convert back to the
original-frame coordinates the user expects, we need per-frame
pad_left, pad_top, scale values plus the original
frame_h / frame_w.
This helper expands those per-frame quantities to per-face tensors
via the frame_idx mapping (which face came from which frame in
the batch).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_data
|
dict from the DataLoader. Must contain |
required | |
frame_idx
|
|
required | |
device
|
device the returned tensors should live on (typically the model's device, so the inversion math runs on-device without an extra round-trip). |
required |
Returns:
| Type | Description |
|---|---|
|
tuple of five |
|
|
|
Source code in feat/utils/image_operations.py
procrustes_align_2d_batched(coords, anchor_idx, ref_anchors)
¶
Batched 2D Umeyama similarity alignment to a fixed reference frame.
For each face, finds the rigid + isotropic-scale transform that best maps
its anchor subset to ref_anchors (least-squares), then applies that
transform to all of the face's landmarks. Mirrors the helper used at
py-feat training time so inference and training canonicalize landmarks
in the same frame.
Used by the dlib-68 โ MP-478 bridge in feat.plotting and any other
consumer that needs to align landmarks to a saved reference (e.g.,
cross-detector landmark normalization). Numpy / float64 internally for
SVD stability; output cast to float32.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
|
required | |
anchor_idx
|
|
required | |
ref_anchors
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
|
|
as the input (after promotion to float32). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in feat/utils/image_operations.py
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | |
procrustes_similarity_torch(src_landmarks, ref_template)
¶
Batched closed-form 2D similarity transform (Umeyama / Procrustes).
For each face's landmarks, finds the rotation + uniform scale +
translation that best maps src โ ref_template in the least-squares
sense. Returns the forward-pixel-coord [B, 2, 3] matrix that
feat.utils.geometry.warp_affine consumes.
Pure torch, fully batched, GPU-friendly. No CPU detour โ keeps the forward graph intact, so this can be wired anywhere downstream of the landmark detector without breaking batched inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_landmarks
|
Tensor
|
|
required |
ref_template
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
|
Tensor
|
ready for |
Source code in feat/utils/image_operations.py
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
procrustes_warp_face_crops(face_crops, face_landmarks, ref_template, out_size=None)
¶
Warp face crops so their landmarks align with a canonical template.
Combines procrustes_similarity_torch (per-face similarity transform
from landmarks โ template) with warp_affine (apply to images).
Output crops are shape-normalized: same anatomical features land on
the same pixel coordinates across faces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face_crops
|
Tensor
|
|
required |
face_landmarks
|
Tensor
|
|
required |
ref_template
|
Tensor
|
|
required |
out_size
|
tuple[int, int] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
Source code in feat/utils/image_operations.py
py_cpu_nms(dets, thresh)
¶
Pure Python NMS baseline
--------------------------------------------------------¶
Fast R-CNN¶
Copyright (c) 2015 Microsoft¶
Licensed under The MIT License [see LICENSE for details]¶
Written by Ross Girshick¶
--------------------------------------------------------¶
Source code in feat/utils/image_operations.py
registration(face_lms, neutral=neutral, method='fullface')
¶
Register faces to a neutral face.
Affine registration of face landmarks to neutral face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
face_lms
|
array
|
face landmarks to register with shape (n,136). Columns 0~67 are x coordinates and 68~136 are y coordinates |
required |
neutral
|
array
|
target neutral face array that face_lm will be registered |
neutral
|
method
|
str or list
|
If string, register to all landmarks ('fullface', default), or inner parts of face nose,mouth,eyes, and brows ('inner'). If list, pass landmarks to register to e.g. [27, 28, 29, 30, 36, 39, 42, 45] |
'fullface'
|
Return
registered_lms: registered landmarks in shape (n,136)
Source code in feat/utils/image_operations.py
reverse_color_order(img)
¶
Convert BGR OpenCV image to RGB format
Source code in feat/utils/image_operations.py
rotvec_to_euler_angles(rotation_vector)
¶
Convert a rotation vector to Euler angles using Kornia in 'xyz'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation_vector
|
Tensor
|
Tensor of shape (N, 3) representing the rotation vectors. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Tensor of shape (N, 3) representing the Euler angles. |