Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Source one: the segmentation’s contours

✅ verified

What this section is for

Segmentation (ch. 1) gives every sub-part a sub-pixel ring. The ring is complete: every stretch of the part’s edge is on it. But a ring is not a line. Along one ring, some arcs are its edge against the background (draw them), some are the seam where a part above presses onto it (that line belongs to the part above), and some are the cut between two same-coloured parts (the source has no line there, so do not draw one). This section cuts the ring into arcs and keeps only the ones worth drawing.

Concepts

Ownership: which part an arc of edge belongs to. Where two parts meet, the edge belongs to exactly one of them – the one above. On the lower one’s ring, that arc is a seam and not its line.

Is there an edge: whether the luminance either side of the ring differs enough. Where the source has no drop there should be no line, even if segmentation cut there.

The rings of the torso and the arm. Blue: its own, with a real edge. Grey: a seam under the part above, which owns that line. Red: between two same-coloured parts, no edge, not drawn.

How it works

Take a point \(p\) about every pixel along the ring, with the normal \(\mathbf{n}\) pointing out of the part, and sample once inside and once outside:

\[ \begin{gathered} p_{\text{in}} = p + d\,\mathbf{n}, \qquad p_{\text{out}} = p - d\,\mathbf{n}, \\ d = 2\ \text{px}. \end{gathered} \]

Ownership: look at \(p_{\text{out}}\)’s label. If it is background or a part further down, the arc is mine; if it is a part further up, the arc is a seam and belongs to that part.

Is there an edge: the luminance difference \(\Delta = |L(p_{\text{in}}) - L(p_{\text{out}})|\). \(\Delta \ge \tau_s\) is a strong edge and \(\Delta \ge \tau_w\) a weak one (\(\tau_s = 10\), \(\tau_w = 5\)). A weak edge does not count on its own: a run of weak points survives only if it contains at least one strong point. This is Canny’s hysteresis threshold, which keeps a real edge from breaking where its contrast dips without letting purely weak noise become a line. An arc whose outside is background counts as having an edge outright.

A gap of fewer than 6 points is ignored and bridged.

The method

  1. Take each sub-part’s ring and compute the normal and the two samples point by point.
  2. Decide ownership from the outer label and drop the seam arcs.
  3. Decide whether there is an edge from the luminance difference and the hysteresis threshold, and drop the arcs with none.
  4. Open arcs in the same line layer whose endpoints are within 8 px and whose directions differ by less than 35 degrees are joined into one.
  5. Smooth (sigma = 1.5) and then least-squares fit into cubic beziers (tolerance 3.0 px, looser than for raster lineart because a contour is shaky to begin with); break the stroke where a join turns by more than 70 degrees; drop anything shorter than 12 px.
  6. Width: radius 0.9 for an outline against the background, 0.7 otherwise. Colour: sampled on the line and darkened to 28%. Width and colour are decided again from the source in the finished painting (ch. 6).

The candidates come out marked with source “contour”, carrying the line layer they belong to, and go into arbitration.

Ch. 4’s per-layer lineart uses the same method, only with the ring of that layer’s completed shape and a label map containing nothing but itself: everything outside is background, so every layer keeps its whole outline.

Common problems

symptomcausewhat to change
a part’s outline breaks at a seamthe arc under the part above belongs to that part, which produces that line itselfexpected; in the finished painting the two layers’ lines meet
a line was drawn between two same-coloured partsa small local drop fooled the hysteresis thresholdoverride it to none, or raise line_min_contrast
a contour line sits one or two pixels off the part’s edgethat is the deviation a tolerance of 3.0 allowsthe fill shapes use the same fit, so nothing is misaligned (ch. 5)

Further reading