BUG: Non-square face thumbnail crop causes distorted avatar scaling near image boundaries
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
Description
In backend/app/utils/face_clusters.py, _calculate_square_crop_bounds() generates coordinates for cropping face avatar images for cluster representation. When faces appear near image edges (left, top, right, or bottom), asymmetric clamping via min() and max() truncates only the out-of-bounds side rather than shifting the bounding box.
This results in a non-square rectangle (e.g., width 170px, height 180px). When passed to _crop_and_resize_face(), cv2.resize(face_crop, (300, 300)) scales the uneven rectangle to a square, distorting facial features and stretching face avatar thumbnails in the cluster gallery view.
Steps to Reproduce
- Import an image where a subject's face is positioned near the edge of the frame (e.g. left margin < 50px).
- Trigger face clustering (
POST /faces/global-recluster). - Check the generated cluster face thumbnail (
face_image_base64). - Result: The face avatar appears horizontally or vertically stretched.
Expected Behavior
The crop bounding box must strictly preserve a 1:1 aspect ratio (x_end - x_start == y_end - y_start == square_size) by sliding inward from the edge rather than truncating one dimension.
Proposed Fix
Refactor _calculate_square_crop_bounds() to calculate a target square size bounded by min(raw_size, img_width, img_height) and shift the window inward when borders are encountered.
Record
- [x] I agree to follow this project's Code of Conduct
👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
[Critical] Unscalable Global Face Re-Clustering Causing OOM & Service Blocking (#810, open) https://github.com/AOSSIE-Org/PictoPy/issues/810 Similarity: 60.9%
-
BUG: Face Collection avatars shrink vertically on small screens (#935, closed) https://github.com/AOSSIE-Org/PictoPy/issues/935 Similarity: 58.4%
-
Adaptive Density-Aware Face Clustering (#1271, closed) https://github.com/AOSSIE-Org/PictoPy/issues/1271 Similarity: 57.8%
Please review before proceeding.
Link your account with Gitcord
Thanks for opening this issue, @akhilmodi29!
To receive Discord notifications and contributor tracking for this organization:
- Join Discord: https://discord.gg/hjUhu33uAn
- In Discord, run
/link akhilmodi29 - Paste the verification code into your GitHub bio (or a public gist)
- Click Verify in Discord (or run
/verify-link akhilmodi29)
Once linked, Gitcord can notify you about assignments, mentions, and more.
— Posted by Gitcord