Digitize endpoint loses semantic content on real photos (photo-to-embroidery not viable) #101
Labels
No labels
blocked:children
blocked:depends-101
blocked:depends-103
blocked:depends-104
blocked:needs-attention
blocked:needs-decision
blocked:no-changes
blocked:preflight
bug
chore
feature-request
in-progress
lint-cleanup
needs-decompose
performance
quality
quickfix
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/easystitch#101
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Feeding a real photograph through
POST /v1/digitizeproduces a geometric/color segmentation that does not preserve recognizable content from the source.Repro
POST the resulting
stitchObjectsthrough/v1/exportto produce a PES file.Observed
Using an 800x600 photo of a dimly-lit floor (a person's foot on lower-left, small orange crumb in middle):
max_colors=4is requested. The output boundary regions form an abstract Voronoi-like decomposition of the photo's value gradient, not a stitched rendition of the source scene.Pre-flattening the input to 4 quantized colors via PIL (
Image.quantize(colors=4)) before upload improves bounds (5 distinct colors in output instead of 33) but still produces abstract segmentation, no recognizable scene.The same pipeline works correctly on already-stylized graphic inputs (e.g. a PNG of a red square, blue hexagon, green triangle, yellow circle on white) — all four shapes are emitted as correct dense tatami fills with the right colors.
Validation already done
head -c 8 /tmp/out.pes->#PES0001(correct Brother PES magic)pyembroidery.read()round-trip -> 21,776 stitches read back on the geometric test, matches HTTPX-Stitch-CountheaderSo the PES file itself is fine. The bug is purely digitization quality on photographic inputs — the pipeline has no concept of semantic regions, only of color-region adjacency.
Root cause hypothesis
The current pipeline (per
element_classifier+physical_optimizerin this repo) takes already-quantized inputs and treats each color cluster as a region. On a photograph that already has thousands of distinct pixel values, the region detector over-segments into fragments that track tiny color shifts in the photo rather than coherent shapes. The existingmax_colorscap is honored byPhysicalOptimizer(verified bytests/test_settings_threading.py::test_physical_optimizer_honors_settings_max_colors) but appears not to be applied to the upstream region detection that establishes the 66-30 split before the optimizer runs.Proposed fix
Add pre-digitize color quantization (k-means or median-cut) that enforces
max_colorsBEFORE the region detector classifies colors. This would:max_colorssetting at the right layerWorkaround for users
Pre-flatten with PIL before upload: