A tattoo stencil is a black line you trace with a needle. So the natural quality metric for a photo-to-stencil converter is ink coverage: how much of the canvas is black. I built one that reports that number to the user, and for a week I trusted it. Then I measured what happens when you erode the mask by one pixel, and the number stopped meaning what I thought.
On a 1000×1000 render of three demo images, line mode put down 1.44%, 2.77%, and 3.91% ink. Solid mode put down 10.04%, 17.95%, and 29.02%. Those look like two settings of the same dial. One erosion by a single pixel separates them completely: 2.5–9.9% of the line-mode ink survives, against 76–90% of the solid-mode ink.
That means the line mask is, on average, one pixel thick. At 1000 pixels wide, a one-pixel line is 0.15 mm on a 15 cm stencil. Nobody can trace that, and no printer holds it.
Two modes, two different problems
The pipeline behind tattoofromphoto.ink is a few hundred lines of PIL and numpy, no OpenCV, no model, running in a worker. It exposes two modes because tattoo artists ask for two different objects.
Line mode is for artists who want an outline to draw inside. It builds a mask with extended difference of Gaussians (XDoG): blur the grayscale twice, subtract the wider blur from the narrower one, and map the difference through a threshold with a tanh rolloff so the transition is soft instead of binary.
def xdog(g, s=1.0, k=1.6, p=0.98, eps=0.1, phi=200.0): g1 = np.asarray(g.filter(ImageFilter.GaussianBlur(s)), np.float32) / 255 g2 = np.asarray(g.filter(ImageFilter.GaussianBlur(s * k)), np.float32) / 255 d = g1 - p * g2 return np.clip(np.where(d >= eps, 1.0, 1.0 + np.tanh(phi * (d - eps))), 0, 1) def line_mask(im, t=0.78): r = xdog(ImageOps.grayscale(im)) m = morph(r > t, "dilate", 1) # widen first, so thin lines survive the erode return morph(m, "erode", 1) The dilate-then-erode pair is a morphological closing. It is there because the raw XDoG mask is worse than one pixel thin in places: thresholding at 0.78 after the tanh rolloff drops diagonal and low-contrast edges to single-pixel dots, and a plain erode would delete them outright. Closing keeps them, but it cannot make them thicker than they were.
Solid mode is for flash-style pieces: big black areas. Local mean thresholding handles the shading, and a dilated XDoG mask catches the edges that local thresholding loses when a dark jacket sits behind a dark subject.
def adaptive_ink(g, radius=25, c=8): arr = np.asarray(g, np.float32) local = np.asarray(g.filter(ImageFilter.BoxBlur(radius)), np.float32) return arr < (local - c) # darker than its neighbourhood by c def solid_mask(im, t=0.78): g = ImageOps.grayscale(im).filter(ImageFilter.MedianFilter(5)) a = adaptive_ink(g) x = xdog(ImageOps.grayscale(im)) > t m = np.logical_or(a, morph(x, "dilate", 1)) return morph(morph(m, "dilate", 1), "erode", 1) The measurement
Three demo images, all resized so the longest side is 1000 px, each rendered in both modes. Ink is the fraction of the canvas that is black. Survival is the share of that ink left after one 3×3 erosion.
| image | mode | ink | survives 1 px erode |
|---|---|---|---|
| simple | line | 1.44% | 2.5% |
| simple | solid | 10.04% | 75.9% |
| balanced | line | 2.77% | 5.7% |
| balanced | solid | 17.95% | 83.0% |
| detailed | line | 3.91% | 9.9% |
| detailed | solid | 29.02% | 90.3% |
Solid mode scales with detail, predictably: more texture in the photo, more ink, because adaptive thresholding treats any local darkening as ink. Line mode also scales, 1.44% to 3.91%, and that is the trap. A user who picks line mode on a detailed photo gets a mask that covers almost 4% of the canvas, and the mask is still one pixel thick. Coverage went up because there are more lines, not because the lines got heavier. The two numbers that a converter would naturally show — coverage and detail — move together and tell you nothing about whether the output is traceable.
The erode number tells you: at 1000 px, the line mode output is a hairline drawing. Print it at 15 cm and every stroke is 0.15 mm. A 3RL needle lays a line around 0.3 mm. So the stencil is thinner than the needle that would follow it.
What changed
Two things, neither of which is a new model.
Render at 2× and let the printer downsample. The mask is computed at 1000 px, then upscaled with LANCZOS to 2000 px before saving. This does not add information, but it stops the stroke from being a single sample wide in the file the artist actually prints; a 2 px stroke at 2000 px is the same physical width, and resampling artifacts no longer eat it.
Gate on ink coverage per mode, not on a global threshold. Above roughly 25% in solid mode on a subject with a busy background, the black areas start merging into a silhouette — the stencil is no longer a set of shapes but a hole in a black field. The worker returns the ink ratio with the image and warns in that range. It is a crude gate, and it is the only one I could defend without a human looking at the output.
Background removal is a hard dependency, not a nice extra. Adaptive thresholding has no idea what a subject is. On a photo with a textured backdrop, every fold and shadow is ink; the 29.02% case above is a detailed demo image, and most phone photos are worse.
What this does not prove
Three demo images are not a benchmark. The XDoG constants (s=1.0, k=1.6, p=0.98, phi=200) are hand-tuned on portrait and animal subjects, and a tattoo artist would likely set them differently for a landscape or a piece of lettering. The 0.3 mm needle figure is a common RL spec, not a measurement of what any particular artist does. And the erode survival tells you about stroke width only — a mask can be two pixels thick everywhere and still be unusable, because the lines cross in the wrong places or the photo's lighting turned a cheek into a shadow.
What the numbers did do is kill the metric I was about to ship. Coverage alone would have let a thin, untraceable stencil pass as a detailed one, because more detail produces more coverage. One erosion pass — three lines of numpy and a division — makes the difference visible, and it runs in a fraction of the time the stencil does.