mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 03:34:23 +00:00
Merge pull request #7187 from dotCooCoo/fix/trace-stair-steps-curves
Image Trace: staircases of longer steps in smooth areas trace as slopes
This commit is contained in:
@@ -156,6 +156,47 @@ under 0.9 px RMS from the gradient's contours, 1.13 px when smoothed as edges, a
|
||||
four corners); `layers::tests` (a ramp, flat colors in palette entries far apart, close flat colors, a
|
||||
thin flat stroke, colors off the line between their entries, and Grayscale's grays, each read from both
|
||||
sides of the crack) and `subpixel::tests` (the rule, and one decision for a whole piece from either side).
|
||||
## Staircases in smooth areas
|
||||
Where a band border in a gradient or a shaded area runs at a slant, its pixels form a staircase whose
|
||||
steps are two or more pixels long. One piece of outline can run along a sharp edge in the image and then
|
||||
along such a border with no junction between them. That piece as a whole is not a contour (see above),
|
||||
and the outline kept a corner at every step. `subpixel::outline` now reads a run of three or more edges of
|
||||
1 to 8 px (`STAIR_MAX`), each turning one way where it starts and the other where it ends, with no
|
||||
junction on it, as a staircase when the run's own cracks pass `subpixel::low_contrast`. A run is cut at
|
||||
any step whose own cracks show half of the step between the two colors or more. The 8 px limit and the
|
||||
one-half cut are VectorCraft's own values. The run's edges are then steps, as one-pixel steps already
|
||||
were: the outline has no corner where two of them meet, and each gives one point, its middle, moved by the
|
||||
mean of its cracks' shifts. Where a run meets an edge that is not a step, the corner between them stays,
|
||||
so a straight edge longer than 8 px next to a staircase stays straight. A straight edge of 8 px or less
|
||||
between two turns of opposite sign is read as one more step of the run. Inside a run, two one-pixel steps
|
||||
between longer ones are read as part of the slope and do not make a notch. A staircase of longer steps,
|
||||
and one whose cracks read as an edge, keep their corners, and Black and White traces do not use the rule.
|
||||
The runs are the same from either side of the border.
|
||||
Measured with the harness below, before and after the change: rows of the "flat colour art" inputs do not
|
||||
change. On gradient and photo inputs, anchors change in 106 rows, 101 of them fewer, by −64% to +6.4%: for
|
||||
example 390 to 142 (Shades of Gray, linear gradients), 1,860 to 1,537 (High Fidelity Photo, linear
|
||||
gradients), 6,766 to 6,542 (High Fidelity Photo, gradient and photo) and 47 to 50 (High Fidelity Photo with
|
||||
Gradients, blurred). On gradient and photo, 6 Colors, 6 Colors with Shapes, with Auto Grouping, without
|
||||
Gradients and enhanced each leave a gap of 0.9 px (was 1.2) and an overlap of 1.0 px (was 0.8). Edge ΔE
|
||||
of Shades of Gray on linear gradients goes from 8.36 to 8.40 (8.39 enhanced), and that of 6 Colors with
|
||||
Gradients on a blurred input from 2.24 to 2.22; other ΔE and edge ΔE values change by 0.01 or less.
|
||||
Lines % changes by −2 to +3, grouped % by −1 to +4, upright % by +1 in 3 rows (Shades of Gray on a blurred
|
||||
input), and specks do not change. On synthetic photos of 800 and 4,000 px traced outside this harness,
|
||||
the corners of rectilinear staircases per 100 px of outline fall from 0.57 to 0.46 and from 1.09 to 0.94
|
||||
with High Fidelity Photo. On the 800 px photo, the 95th percentile of the pixel difference with High
|
||||
Fidelity Photo rises from 6.33 to 6.67, and 16 Colors leaves 2 staircases of steps of 2 px or more where
|
||||
it left none. The tables below are the previous measurement, not a rerun.
|
||||
Tests on code-drawn outlines in `subpixel::tests`:
|
||||
`a_staircase_of_longer_steps_in_a_smooth_area_becomes_the_slope_through_its_steps` (a piece with a
|
||||
staircase of 2 × 3 px steps in a smooth area, a straight run and the same staircase on a sharp edge: the
|
||||
first gives its steps' middles and none of its corners, the straight run keeps the corners at its ends, the
|
||||
second staircase keeps its corners, both regions get the same points, and 10 px steps keep their corners
|
||||
in a smooth area), `a_staircase_that_runs_on_from_a_smooth_area_into_an_edge_keeps_the_edges_corners`,
|
||||
`a_staircase_whose_cracks_do_not_read_as_a_contour_keeps_its_corners` (two flat colors),
|
||||
`a_staircase_step_moves_by_the_mean_shift_of_its_cracks`,
|
||||
`a_staircase_of_mixed_one_pixel_and_longer_steps_is_one_slope_without_a_notch`,
|
||||
`a_run_of_two_steps_keeps_its_corners`, `a_junction_on_a_step_ends_the_staircase_there` and
|
||||
`a_step_whose_cracks_read_as_an_edge_ends_the_staircase_there`.
|
||||
## A simpler contour walk
|
||||
`contour::trace_mask` follows each region's outline along the pixel cracks with the inside on the
|
||||
right. It used to build a table of outgoing directions for every pixel corner in a raster pass and
|
||||
|
||||
@@ -1355,6 +1355,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Image Trace, notches read only their own piece:** the notch rule of `subpixel::outline` reads only the shared piece, so both regions of an edge cut a corner pixel alike and leave no gap; a code-drawn noisy multi-colour coverage test in `crates/trace` (see [quality notes](image-trace-quality.md#notches-read-only-their-own-piece)).
|
||||
- **Image Trace, same shift from either side of an edge:** a crack's sub-pixel shift is averaged from its two sides, so abutting regions on one- and two-pixel slivers get the same points and leave nothing uncovered; code-drawn regressions in `crates/trace` (see [quality notes](image-trace-quality.md#same-sub-pixel-shift-from-either-side-of-an-edge)).
|
||||
- **Image Trace, band borders in smooth areas:** in Color and Grayscale traces, a border between two colors where the image changes gradually is the contour of a smooth area, by VectorCraft's own rule (`subpixel::low_contrast`, distances measured in RGB, 0 to 255 a channel): next to the border the image makes less than half the step between the two colors; it makes more of the step a few pixels further out, or changes by a distance under 12 (about 7 levels in each channel of a gray); the pixels on each side change too; and its whole change next to the border is under twice its change from one color towards the other, or under 24. Grayscale reads each pixel as its gray, for this rule and for every edge's sub-pixel position. Such a border is smoothed over about 4 px instead of 0.5 px (0.9 px for an edge without anti-aliasing), keeps no corners and is fitted to at least 0.5 px, so band borders in photos and gradients follow the image's contours with fewer anchors; without Shapes, both colors beside it share the same curve. Color traces of clean flat-color art and Black and White traces are unchanged, Grayscale traces of colored art place their edges closer to the art's outlines, and noisy flat-color art can take fewer anchors where noise splits a color into bands; see [quality notes](image-trace-quality.md#band-borders-in-smooth-areas). Tests: `tests::the_borders_of_a_gradients_bands_follow_its_contours`, `layers::tests` and `subpixel::tests` in `crates/trace`. Scores and hours unchanged.
|
||||
- **Image Trace, staircases in smooth areas:** in Color and Grayscale traces, a staircase of three or more steps of 1 to 8 px along a border between two colors, where the image changes gradually by the same rule (`subpixel::low_contrast`, read for the staircase alone, which ends at any step that shows half of the step between the two colors or more; the 8 px limit and the one-half cut are VectorCraft's own values), is traced as the slope through the middles of its steps with no corner at each step, also on an outline that runs on along a sharp edge in the image. The corner where a staircase meets a straight edge longer than 8 px stays. Longer steps, staircases along a sharp edge and Black and White traces keep their corners; 6 Colors on gradient and photo leaves a gap of 0.9 px (was 1.2) and an overlap of 1.0 px (was 0.8), and High Fidelity Photo with Gradients on a blurred input takes 50 anchors (was 47); see [quality notes](image-trace-quality.md#staircases-in-smooth-areas) for these and the other rows that got worse. Tests: eight `subpixel::tests` in `crates/trace`, starting with `a_staircase_of_longer_steps_in_a_smooth_area_becomes_the_slope_through_its_steps`. Scores and hours unchanged.
|
||||
- **Image Trace, cut-out edges:** in Color and Grayscale, a semi-transparent pixel (alpha 128 to 254) on the edge of a cut-out image, beside a pixel that is less than half opaque, traces as a color of the fully opaque pixels within two pixels of it when its own color is that color or a darker shade of it, and of several such colors, as the one the most of those pixels have (art across a transparent gap does not count), so a darkened edge tone no longer traces as a 1 px sliver of an unrelated palette color, while a thin semi-transparent outline of another color keeps its own; code-drawn cut-out, opaque-edge and thin-outline tests in `crates/trace`.
|
||||
- **Image Trace, cut-out edges choose no color:** in Color and Grayscale, the edge pixels that take the color beside them, and the semi-transparent pixels within two pixels of them whose color is also the opaque art's color blended with the background, do not count when the palette or the grays are chosen, so the edge of a cut-out image no longer adds a second shade of a color to Auto Color's palette, takes away an outline's color or takes a gray of its own; beside those pixels, the anti-aliasing between a color and an outline drawn along the edge is no color of Auto Color's own when it lies at least 0.45 of the way from the color to the outline and at least one in 32 of its pixels has both around it (edge pixels that choose no color count when they lie within 2.5 Oklab × 100 of the nearest of those colors): its pixels trace as the outline, so a thin outline stays a ring of few pieces, except beside an outline along the edge with a region of 8 pixels of its own, where each takes the nearer of the two, so a wider outline is not drawn wider; an outline over the edge in the color of other art traces in that color, while an opaque rim drawn along the edge keeps its color, also where other art reaches it; a thin semi-transparent outline of another color still counts, and opaque images trace as before; code-drawn cut-out outline, rim, opaque line and grayscale edge tests in `crates/trace`.
|
||||
- **Image Trace, simpler contour walk:** `contour::trace_mask` works out each turn from the pixels during the walk, with no precomputed direction table and no assertion; identical loops to the previous walk on every 4 × 4 mask (see [quality notes](image-trace-quality.md#a-simpler-contour-walk)).
|
||||
|
||||
Reference in New Issue
Block a user