Search only the max-fitting crop window, including edge positions
Edge energy is non-negative, so the 85% and 70% candidate windows could never outscore the full-size window containing them; drop them. Also always evaluate the last x/y position so a subject touching the right or bottom edge isn't cut by up to one step of grid misalignment. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ac9a0b43a8
commit
36782f15a1
2 files changed
+31
-26
No files matched your search
@@ -182,7 +182,7 @@ Algorithm (`SaliencySmartCropper`):
|
||||
2. Compute the **max-fitting centered rect** at the target aspect. This is the upper bound on crop size and the fallback if any later step throws.
|
||||
3. Downscale a clone of the source to **256 px on the long edge** (cheap analysis canvas).
|
||||
4. Compute per-pixel **Sobel magnitude** on Rec. 601 luma, build a **summed-area table** for O(1) rectangle sums.
|
||||
5. Slide a target-aspect window over the downscaled image at three sizes (100%, 85%, 70% of the max-fitting size) with an 8 px step, pick the position with maximum total edge energy.
|
||||
5. Slide the max-fitting target-aspect window over the downscaled image with an 8 px step (always including the last position on each axis, so edge-hugging subjects aren't missed), pick the position with maximum total edge energy. Only one window size is searched: edge energy is non-negative, so a smaller window can never outscore a larger one containing it.
|
||||
6. Scale the winning rect back to source coordinates, clamp to image bounds, return.
|
||||
|
||||
Failure mode: the whole `ComputeCropRect` is wrapped in `try/catch`; on any exception we log a warning and return the centered max-fitting rect. A bad photo must never 500 the upload — same doctrine as MQTT failure being non-fatal.
|
||||
|
||||
Reference in new issue
Block a user