Skip to content

Feature: use neighboring colors to improve Auto-paint stacks and predictions #226

Backlog

Description

@vycdev

Summary

Add an opt-in Auto-paint option that takes the image context into account when choosing stacks and judging predictions. The same color can look different depending on what's around it, so an Auto-paint result that scores well color by color can still look wrong where colors meet, and the reverse: a color the filaments can't reach exactly can still look right next to its neighbors.

The context comes from the image itself: which colors touch, how long their shared borders are, and how big each region is.

The effect

  • Simultaneous contrast (chromatic induction): a color looks pushed away from its surroundings. The same gray looks lighter on black than on white, and slightly yellow when it's surrounded by blue. It's strongest for small areas inside large ones.
  • Assimilation: at fine detail (thin stripes, small dots, height dithering) the opposite happens, and colors blend toward their neighbors instead.
  • People notice edges between colors more than absolute values, so keeping the difference across an edge often matters more than getting each side exact.

The problem today

Auto-paint scores each target color on its own: CIEDE2000 between the target and the predicted stack color, weighted by how much of the image the color covers. Where that color sits plays no part.

Preserve color separation (mapTargetsWithSeparation in src/lib/autoPaint.ts) is the only scoring that looks at more than one color. It keeps source colors from collapsing onto the same printable color, but it doesn't know which colors touch or how much.

So when the loaded filaments can't reach the image's colors:

  • Two touching colors can drift in different directions, so the edge between them gets weaker or stronger than in the image, even though each color's own ΔE looks fine.
  • Auto-paint can't choose a nearby reachable color because it would look right in its surroundings.

Possible approaches (cheapest first)

  1. Keep contrast between neighboring colors. Build an adjacency table from the quantized image: for each pair of colors, how long their shared border is. Add a penalty when the predicted Lab difference across a border drifts from the original difference, weighted by border length. This doesn't need a perception model. It shifts touching colors together instead of letting them drift apart, and it builds naturally on Preserve color separation.
  2. Model the surround. Before scoring, shift each target toward how it looks in its original surroundings, and the prediction toward how it looks in its printed surroundings, then score perceived color against perceived color. The textbook model only adjusts for the average brightness of the whole background (CIECAM02's background setting), so doing it per region needs a simple local induction model. Its strength should depend on region size and border length.
  3. Model blending at fine detail. Use a spatial model such as S-CIELAB, which blurs each color channel the way the eye does at a given viewing distance. This covers assimilation in fine detail and height dithering, but it needs a viewing-distance setting and makes scoring slower.

The suggestion is to start with 1 behind an experimental toggle, and add 2 on top only if 1 proves worth it.

Guardrails

  • Off by default, and deterministic. If any search randomness is involved, it reuses the existing seed.
  • Capped like per-region stacks (Feature: give each color region its own filament stack #151): no color may get more than a fixed ΔE worse in absolute terms because of the context term.
  • No change to geometry, layer snapping or 3MF export. Only stack choice and predicted colors change.
  • Must work with Flat Paint, per-region stacks and height dithering, or say clearly where it doesn't apply.

Validation

  • Unit tests on small synthetic images: a gray patch on different backgrounds, and two touching colors that can't be reached exactly. Check that the edge difference is kept within a tolerance and that the absolute cap holds.
  • Compare scores and chosen stacks with the option off and on, on the existing Auto-paint golden fixtures.
  • Check against calibration evidence where possible. The final judgement needs test prints, because the 3D preview is also seen in context on screen and shows part of the effect by itself.

Open questions

  • Does the option apply to both stack choice and the predicted colors shown in the UI, or only to stack choice?
  • Is a fixed viewing distance good enough, or does approach 3 need a setting?
  • How is the option explained in the UI and the Auto-paint guide without color-science terms?

Activity

  1. added
    enhancement
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions