Add saliency-based smart crop before resize
Replace the center-crop cover resize with a Sobel edge-density search that picks the target-aspect window with the most edge energy, so a subject off-center isn't sliced when the input aspect differs from the frame's. Failures fall back to the centered crop. Golden fixtures are regenerated and an asymmetric-edges input exercises the bias. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
675d206234
commit
ac9a0b43a8
24 files changed
+340
-24
No files matched your search
@@ -32,13 +32,14 @@ Both forms produce identical downstream behavior.
|
||||
For each accepted image, the service performs the following stages in order:
|
||||
|
||||
1. **Decode** the input into an in-memory RGBA bitmap.
|
||||
2. **Resize** to the frame's resolution using `cover` semantics — scale the input so it fully covers the target rectangle, then center-crop overflow. Aspect ratio is preserved; no stretching.
|
||||
3. **Dither** the bitmap against a palette built from the frame's `color` (display) values, using the dithering algorithm configured for that frame. Output of this stage contains only colors from the display palette.
|
||||
4. **Remap** each pixel from its display color to its corresponding `deviceColor` per the palette. Output of this stage contains only colors from the device-color palette.
|
||||
5. **Rotate** the bitmap 90° clockwise if the frame's orientation is `portrait`. The output dimensions always match the frame's declared resolution (e.g., 1600×1200) regardless of orientation.
|
||||
6. **Encode** as an **indexed PNG** with a palette of the frame's device colors, using the smallest bit depth that fits the palette size.
|
||||
7. **Persist** the resulting PNG to storage, replacing any previous image for the same frame **atomically** (no half-written file is ever observable via the HTTP fetch endpoint).
|
||||
8. **Notify** by publishing an MQTT message announcing that a new image is available.
|
||||
2. **Smart crop** to the frame's target aspect ratio. The service selects the source-coordinate crop rectangle by saliency (Sobel edge density): the rectangle of target aspect with the highest total edge energy is kept. This preserves the most visually interesting region of the source when the input aspect ratio differs from the frame's. If the input already matches the frame's aspect ratio (within a small tolerance), no cropping is performed. Smart-crop failure is non-fatal: on any internal error the service falls back to a centered max-fitting crop and logs a warning — a difficult photo never fails the upload.
|
||||
3. **Resize** the cropped bitmap to the frame's resolution. Aspect ratio is preserved by the preceding crop, so this stage is a pure scale.
|
||||
4. **Dither** the bitmap against a palette built from the frame's `color` (display) values, using the dithering algorithm configured for that frame. Output of this stage contains only colors from the display palette.
|
||||
5. **Remap** each pixel from its display color to its corresponding `deviceColor` per the palette. Output of this stage contains only colors from the device-color palette.
|
||||
6. **Rotate** the bitmap 90° clockwise if the frame's orientation is `portrait`. The output dimensions always match the frame's declared resolution (e.g., 1600×1200) regardless of orientation.
|
||||
7. **Encode** as an **indexed PNG** with a palette of the frame's device colors, using the smallest bit depth that fits the palette size.
|
||||
8. **Persist** the resulting PNG to storage, replacing any previous image for the same frame **atomically** (no half-written file is ever observable via the HTTP fetch endpoint).
|
||||
9. **Notify** by publishing an MQTT message announcing that a new image is available.
|
||||
|
||||
### 3.3 Output delivery
|
||||
|
||||
|
||||
Reference in new issue
Block a user