A paint-by-numbers template turns a continuous-tone photograph into flat color regions, each labeled with a number that maps to a paint: a limited palette, areas big enough to paint, a legible number on every one. Here is what this tool actually does at each stage.
Preparing the Photo: Painted Shapes and Deep Shadows
Choosing colours straight from a photograph turns every texture — stone, foliage, a rippled sea — into a mosaic of same-sized tiles, because each pixel picks its nearest palette colour on its own. With Painted shapes on (the default), the photo first goes through an iterated bilateral filter: each pixel is averaged with neighbours that are both near it and similar in colour, so a texture flattens into its own mean while the edge between two different colours stays sharp. A sea becomes a few clean bands, a cypress one shape with its inner tones. Deep shadows (off by default) pulls the tones darker than the photo's median further down and leaves the brighter half and the colour saturation alone, which adds depth without crushing dark areas into a single black patch.
K-Means in CIELAB, Seeded With K-Means++
K-means partitions the pixels into k groups, each joining the cluster whose center is nearest; that center is the mean of its members, which is why every palette color is the average of the pixels it stands for. Seeding uses k-means++ — each new seed picked with probability proportional to its squared distance from those already chosen — so two clusters do not chase one color while a whole hue goes unrepresented. All of it runs in CIELAB, where distance approximates perceived difference.
Keeping Palette Colors Apart — and What It Costs
K-means alone still spends slots where the pixels are, not where the interest is: skin dominates a portrait, so a dozen entries can land in browns while a lip red never wins one. The tool therefore enforces a minimum perceptual separation, using the same threshold as the “Merge similar colors” control. Over three rounds it looks for the closest pair of centroids nearer than that threshold, and for a bin of the image's own colors further than the threshold from every centroid. When both exist, the pair collapses into its area-weighted mean — the color you would get mixing the two paints in proportion to the canvas each covers — and the freed centroid is re-seeded on the best-scoring candidate bin, scored by area times distance to its nearest centroid.
This is a deliberate trade, not a universal improvement. On a photograph that really is all one hue, or whose palette is already well spread, one side of the trade is unavailable and the centroids are left exactly as k-means produced them. When it does fire, you gain a color that was absent and pay in overall fidelity: measured on three real portraits, one gained a missing blue and a second lip red and improved overall, one improved slightly, and one made its lips paintable while its mean color error got worse. Set the control to Off to keep the palette k-means measured.
From Colors to Paintable Regions
Once every pixel carries a palette number the image splits into connected regions of the same number, and two passes clean that up. The first asks whether two neighbours are really one color to someone holding a brush: it walks adjacent pairs in order of how close they are in CIELAB, merges any pair within the threshold into their area-weighted blend, and repeats — merging changes the survivor's color, which can bring a third neighbour into range. That is what stops a face breaking into a mosaic of slivers, and it runs first so everything downstream sees fewer, less thin regions. The second pass absorbs any region left with no paintable interior into its closest neighbour in color.
Outlines: Boundary Edges, Then Curves
Outlines here are not produced by edge detection. Every unit edge of the pixel lattice where the two adjacent regions differ is collected as a boundary edge, and those edges are stitched into closed rings — which is why neighbours share one gap-free line rather than two nearly-coincident ones. Traced that way, a border is a staircase, and a small region is a polygon of hard corners. So before anything is simplified, the whole network of borders is smoothed at once with Taubin smoothing: every border point, including the junctions where three regions meet, moves toward the average of its neighbours along the border, then a slightly larger step back out, which is what stops the shapes from shrinking the way plain averaging would. Each point has one position, read by every region that touches it, so neighbours stay gap-free; the edges of the sheet are held still so its corners stay square. “Smooth edges” sets how many passes run (4, 8 or 14) and the tolerance of the Ramer–Douglas–Peucker simplification that follows. What remains is drawn with quadratic Bézier curves anchored on the midpoints of each edge, with only the junctions and the sheet border kept as corners.
Placing the Numbers, and Why Some Need a Leader Line
Each number has to sit clearly inside its region, even for a curved or L-shaped area whose geometric center falls outside it. The tool computes a distance transform per region and places the number at the "pole of inaccessibility" — the interior point farthest from any border. The distance there is the region's inscribed radius. Both are measured on the shape as it is drawn — the smoothed, curved border, rasterized at twice the segmentation resolution — not on the pixel map underneath, which a smoothed border can sit a pixel away from; a region the smoothing leaves too thin for its number is merged into its neighbour once more. Whether a number fits is only meaningful relative to the size you print: a digit of your chosen millimetre height occupies (mm ÷ 25.4) × DPI pixels on the sheet, and dividing by the output pixels per segmentation pixel converts that into the radius's own units. A number is a box, not a dot: two digits are about one and a half times as wide as they are tall, so a region fits its number when the box's diagonal fits inside the inscribed circle. A region that cannot hold its number gets a leader line: its label is placed by trying sixteen directions and several distances, nearest first, keeping the first spot that covers no other number and stays on the sheet, and a white halo keeps it readable over the outlines it crosses. Because the requirement is anchored to a physical millimetre, the same photograph needs more leader lines on A5 than on A3. By default “Merge to fit every number” is on, so there are none: it folds regions that cannot hold the palette's longest number into a neighbour one at a time, smallest first — into the one sharing most of its border, preferring a similar colour — and measures that neighbour again, because absorbing a speck often gives a thin region exactly the room it lacked. The floors are measured on paper, so a bigger canvas keeps more detail when merged. With the Faces focus a face keeps its finest features on leader lines.
When a Photo Is Too Much Work
All of this runs in your browser, and a segmentation ceiling protects the tab from a run that would never finish. High-detail photographs — sand, fur, foliage — used to cross it; the color-merging stage is where such a run spends nearly all its time, and it is now dramatically cheaper, so a photo that took over a minute in Firefox and gave up finishes in a few seconds. The ceiling has not gone away, because some photograph will always be too much work. What changed is that hitting it now names the two settings that measurably reduce the work — fewer colors, and a higher “Merge similar colors” value — instead of leaving an empty panel.
Related tools on the same colour engine
To see the exact palette this generator would pick — in HEX, RGB and HSL, with each colour's share of the picture — run the photo through the colour palette generator first; it is handy for matching paints or printing a swatch card next to the canvas. And if what you actually want is the filled, coloured vector of a logo or flat illustration rather than a numbered template, the image to SVG converter shares this tool's region tracing but keeps the fills.