From dd1a6a45bd2cf9a00c722d4e0c1bc63dd7b36dde Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 07:54:58 -0800 Subject: [PATCH] Image Trace: Full Tone merges and cuts with less repeated work merge_mixed works out each color's Oklab value once, and again only for the color that takes in another, and skips the distance for two colors mixed too little to merge under either test. Median cut plans the cut of a narrow box only while there are fewer boxes than the least count. The traced SVGs are byte-identical for the six presets on 19 test images; High Fidelity Photo's trace time for all 19 falls from 35.3 to 31.5 s. The quality notes give High Fidelity Photo in Full Tone its own section, say how far merging can bring the color count below the least count, and state the measured trace time, memory and cost on grainy flat grays. A test checks that a grainy dark gray traces with about as many colors and shapes as a grainy light one, and the noisy ramp test's comment gives the counts this tree measures. --- crates/trace/src/quantize.rs | 37 ++++++++----- crates/trace/src/quantize/palette.rs | 16 +++--- crates/trace/src/tests.rs | 23 ++++++-- docs/image-trace-adjustments.md | 9 ++-- docs/image-trace-quality.md | 78 ++++++++++++++++------------ docs/target-app-parity.md | 2 +- 6 files changed, 107 insertions(+), 58 deletions(-) diff --git a/crates/trace/src/quantize.rs b/crates/trace/src/quantize.rs index 2a0deeb013..a115cd3ce3 100644 --- a/crates/trace/src/quantize.rs +++ b/crates/trace/src/quantize.rs @@ -315,7 +315,7 @@ pub(crate) fn tests_oklab(c: [u8; 3]) -> [f64; 3] { #[derive(Clone, Copy, PartialEq, Eq, Debug)] enum Alike { /// Close in RGB: under 30 levels apart and thoroughly mixed, or under 12 and mixed in patches. - /// A limited palette's colors are few and far apart, so two this close are one color. + /// Used for Grayscale and for every Color palette but Full Tone (Automatic included). Rgb, /// Close to the eye: under [`FULL_TONE_ALIKE`] apart in Oklab and thoroughly mixed, or under /// [`FULL_TONE_PATCHES`] and mixed in patches (compression blocks). Full Tone's neighboring tones @@ -335,13 +335,13 @@ const FULL_TONE_PATCHES: f64 = 1.5; /// `q` with the colours that noise made of one colour merged, largest mix first. /// /// Asked for more colours than a picture has, k-means splits a flat colour along its noise, and -/// the two halves would trace as specks of one all over the other. Such halves are close (under 30 -/// levels apart: noise is about as strong in a dark colour as in a light one, so the distance is -/// taken in RGB) and thoroughly mixed: the pixels of the lesser one have, on average, more than -/// half a neighbour of the other each; or they are closer still (under 12 levels) and mixed in -/// patches (compression blocks). The bands of a gradient are close too, but each keeps to itself -/// and they stay apart. The colours in `keep` merge with none. With [`Alike::Seen`], the distances are -/// taken in Oklab (see [`FULL_TONE_ALIKE`] and [`FULL_TONE_PATCHES`]). +/// the two halves would trace as specks of one all over the other. Such halves are close and +/// thoroughly mixed: the pixels of the lesser one have, on average, more than half a neighbour of +/// the other each; or they are closer still and mixed in patches (compression blocks). The bands +/// of a gradient are close too, but each keeps to itself and they stay apart. The colours in +/// `keep` merge with none. Close is under 30 RGB levels apart for thoroughly mixed colours and +/// under 12 for patches with [`Alike::Rgb`], and in Oklab under [`FULL_TONE_ALIKE`] and +/// [`FULL_TONE_PATCHES`] with [`Alike::Seen`]. fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]], alike: Alike) -> Quantized { let k = q.palette.len(); // A rare colour kept on purpose (see `rare_colours`) is distinct by choice: it merges with none. @@ -364,6 +364,13 @@ fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]], alike: Alike) } } let mut color: Vec<[f64; 3]> = q.palette.iter().map(|c| c.map(f64::from)).collect(); + // Each colour in Oklab, for `Alike::Seen`, worked out once and again only for a colour that + // takes in another. + let mut lab: Vec<[f64; 3]> = if alike == Alike::Seen { color.iter().map(|&c| oklab(c)).collect() } else { vec![] }; + let seen_apart = |lab: &[[f64; 3]], a: usize, b: usize| match (lab.get(a), lab.get(b)) { + (Some(la), Some(lb)) => (0..3).map(|c| (la[c] - lb[c]).powi(2)).sum::().sqrt(), + _ => f64::INFINITY, + }; // Which colour each has merged into (itself when none). let mut into: Vec = (0..k).collect(); loop { @@ -374,15 +381,18 @@ fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]], alike: Alike) continue; } let mixed = touch[a * k + b] / count[a].min(count[b]); + // Two colours this little mixed merge under neither test. + if mixed <= 0.15 { + continue; + } let merges = match alike { Alike::Rgb => { let apart = (0..3).map(|c| (color[a][c] - color[b][c]).powi(2)).sum::().sqrt(); - mixed > 0.5 && apart < 30.0 || mixed > 0.15 && apart < 12.0 + mixed > 0.5 && apart < 30.0 || apart < 12.0 } Alike::Seen => { - let (la, lb) = (oklab(color[a]), oklab(color[b])); - let apart = (0..3).map(|c| (la[c] - lb[c]).powi(2)).sum::().sqrt(); - mixed > 0.5 && apart < FULL_TONE_ALIKE || mixed > 0.15 && apart < FULL_TONE_PATCHES + let apart = seen_apart(&lab, a, b); + mixed > 0.5 && apart < FULL_TONE_ALIKE || apart < FULL_TONE_PATCHES } }; if merges && best.is_none_or(|x| mixed > x.0) { @@ -392,6 +402,9 @@ fn merge_mixed(q: Quantized, w: usize, h: usize, keep: &[[u8; 3]], alike: Alike) } let Some((_, a, b)) = best else { break }; color[a] = [0, 1, 2].map(|c| (color[a][c] * count[a] + color[b][c] * count[b]) / (count[a] + count[b])); + if let Some(l) = lab.get_mut(a) { + *l = oklab(color[a]); + } count[a] += count[b]; count[b] = 0.0; into[b] = a; diff --git a/crates/trace/src/quantize/palette.rs b/crates/trace/src/quantize/palette.rs index 828217ca55..63c8fe9a06 100644 --- a/crates/trace/src/quantize/palette.rs +++ b/crates/trace/src/quantize/palette.rs @@ -328,8 +328,10 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64, least: usi widest: f64, best: Option<(f64, Vec, usize)>, } - // Boxes no wider than this are never cut. - let narrowest = if least > 0 { 0.0 } else { spread.max(0.0) }; + // Boxes no wider than `spread` are cut only while there are fewer than `least` boxes. A box made + // when there are already `least` boxes or more is never cut unless it is wider, so its cut is + // not planned. + let narrowest = |boxes_after: usize| if boxes_after < least { 0.0 } else { spread.max(0.0) }; // How much of a cut's gain counts when its sides' mean colors are `a` and `b`: all of it when // they look different or either is not a dark gray, less as two dark grays look more alike. let dark_gray = |c: [f64; 3]| c[0] < DARK && c[1].hypot(c[2]) < GRAY; @@ -340,7 +342,8 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64, least: usi } ((0..3).map(|q| (a[q] - b[q]).powi(2)).sum::() / (apart * apart)).min(1.0) }; - let plan = |bins: Vec| { + let plan = |bins: Vec, boxes_after: usize| { + let narrowest = narrowest(boxes_after); let mut best: Option<(f64, Vec, usize)> = None; let widest = (0..3) .map(|ch| { @@ -388,7 +391,7 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64, least: usi } Cut { bins, widest, best } }; - let mut boxes = vec![plan((0..used.len()).collect())]; + let mut boxes = vec![plan((0..used.len()).collect(), 1)]; while boxes.len() < k { let gain = |c: &Cut| c.best.as_ref().map_or(f64::NEG_INFINITY, |b| b.0); // The boxes wider than `spread` first; when none is left and there are fewer than `least`, @@ -403,8 +406,9 @@ fn median_cut_apart(used: &[Used], k: usize, spread: f64, apart: f64, least: usi }; let Some((_, mut sorted, at)) = boxes.swap_remove(bi).best else { break }; let tail = sorted.split_off(at); - boxes.push(plan(sorted)); - boxes.push(plan(tail)); + let after = boxes.len() + 2; + boxes.push(plan(sorted, after)); + boxes.push(plan(tail, after)); } boxes .iter() diff --git a/crates/trace/src/tests.rs b/crates/trace/src/tests.rs index 1cc61e2bdf..694892a8a6 100644 --- a/crates/trace/src/tests.rs +++ b/crates/trace/src/tests.rs @@ -1726,7 +1726,7 @@ fn jitter(x: u32, y: u32, salt: u32) -> f64 { } #[test] -fn full_tone_keeps_a_noisy_ramps_neighboring_tones() { +fn full_tone_keeps_more_of_a_noisy_ramps_tones() { // Gray to green with grain: Full Tone's neighboring tones are close in RGB and mixed along // their borders, and still look different. let img = Raster::from_fn(256, 96, |x, y| { @@ -1734,8 +1734,8 @@ fn full_tone_keeps_a_noisy_ramps_neighboring_tones() { [v(0, 100.0, 0.0), v(1, 40.0, 0.7), v(2, 100.0, 0.0), 255] }); let params = TraceParams { mode: Mode::Color, palette: Palette::FullTone, color_detail: 85.0, ..TraceParams::default() }; - // Median cut gives at least 85 (one per step of Color detail); merged where they look alike, 6 - // are left, and merged as close RGB colors, 5 would be. + // Median cut gives at least 85 (one per step of Color detail). Merging the ones that look alike + // leaves 6 (one per 30 or so levels of the ramp); merging close RGB colors would leave 4. let n = quantize(&img, ¶ms).palette.len(); assert!(n >= 6, "{n} tones"); // Automatic traces continuous tone without Full Tone's least count and keeps merging close RGB colors. @@ -1743,6 +1743,23 @@ fn full_tone_keeps_a_noisy_ramps_neighboring_tones() { assert!(automatic < n, "{automatic} tones with Automatic, {n} with Full Tone"); } +#[test] +fn full_tone_traces_a_noisy_dark_ground_like_a_light_one() { + // A gray ground with up to 8 levels of grain a channel. The same grain lies farther apart in + // Oklab in a dark gray than in a light one; the dark ground still takes about as many colors + // and shapes as the light one (32 and 53 against 31 and 52 when measured). + let ground = |gray: f64| { + let img = Raster::from_fn(192, 128, |x, y| { + let c = |k: u32| (gray + 8.0 * jitter(x, y, k)).round().clamp(0.0, 255.0) as u8; + [c(0), c(1), c(2), 255] + }); + trace(&img, &preset("High Fidelity Photo").unwrap()) + }; + let (dark, light) = (ground(28.0), ground(200.0)); + assert!(dark.palette.len() <= light.palette.len() + 2, "{} colors dark, {} light", dark.palette.len(), light.palette.len()); + assert!(dark.paths.len() <= light.paths.len() + 6, "{} shapes dark, {} light", dark.paths.len(), light.paths.len()); +} + #[test] fn full_tone_merges_a_flat_colors_compression_blocks() { // Three flat colors stored in 8 × 8 blocks, each block off by up to 8 levels a channel, with a diff --git a/docs/image-trace-adjustments.md b/docs/image-trace-adjustments.md index 92cd467cab..06c4799105 100644 --- a/docs/image-trace-adjustments.md +++ b/docs/image-trace-adjustments.md @@ -24,8 +24,9 @@ Logo, Line Art and Outline, and 50 in the other eight. Noise is 1 px in Technica and 16 Colors, 10 in Low Fidelity Photo, 15 in 3 Colors and Shades of Gray, 20 in Sketched Art, Line Art and Outline, 25 in Default, and 90 in Silhouettes (see [image-trace-quality.md](image-trace-quality.md#preset-paths-corners-and-noise)). High Fidelity Photo -traces with Palette › Full Tone at Color detail 85 and Method › Abutting (VectorCraft's own values); Low -Fidelity Photo traces with a Limited palette of 20 colors, Overlapping. +traces with Palette › Full Tone at Color detail 85 and Method › Abutting (VectorCraft's own values; see +[image-trace-quality.md](image-trace-quality.md#high-fidelity-photo-in-full-tone)); Low Fidelity Photo +traces with a Limited palette of 20 colors, Overlapping. Sliders apply on release, and their numeric fields can be edited directly. Each committed adjustment re-traces the selected object as one undo step and changes the preset to Custom. @@ -86,8 +87,8 @@ color nearest to it in lightness and hue, with a difference in hue or chroma cou as much as one in lightness, so a gray or a muted brown takes a black, white or other neutral library color rather than a saturated color of the same lightness. **Abutting and Overlapping.** Abutting is the default Method, and the Default, Auto Color, High Fidelity -Photo, 3 Colors, 6 Colors and 16 Colors presets use it. With Abutting, two neighboring colors share one exact edge. The -canvas smooths the edges of each path on its own, so each of the two paths covers only part of the +Photo, 3 Colors, 6 Colors and 16 Colors presets use it. With Abutting, two neighboring colors share one +exact edge. The canvas smooths the edges of each path on its own, so each of the two paths covers only part of the pixels along that edge, and a thin line of the background can show between the colors. Web browsers and PDF viewers usually draw an exported SVG or PDF file the same way and show the same line. Raster exports (PNG, JPEG, TIFF and the other bitmap formats) with None anti-aliasing do not show it at any diff --git a/docs/image-trace-quality.md b/docs/image-trace-quality.md index 7977d5b919..ab8ee313d7 100644 --- a/docs/image-trace-quality.md +++ b/docs/image-trace-quality.md @@ -83,8 +83,9 @@ gradient, texture, sensor noise): Photo trace was 86,000 anchors under the old limit; a noisier scan of the same size would have been refused. At 8,000,000 anchors a trace keeps about 0.7 GB, with a peak of about 0.9 GB while tracing. The preset rows were measured with the earlier preset values: High Fidelity Photo at Paths 90, Corners 25 -and Noise 4 with a Limited palette of 64 colors and Overlapping, Low Fidelity Photo at Paths 60, Noise 12 and 16 Colors at Paths 70, Corners 55 and Noise 10 -(see [Preset Paths, Corners and Noise](#preset-paths-corners-and-noise)). +and Noise 4 with a Limited palette of 64 colors and Overlapping, Low Fidelity Photo at Paths 60, Noise 12 +and 16 Colors at Paths 70, Corners 55 and Noise 10 (see [Preset Paths, Corners and +Noise](#preset-paths-corners-and-noise) and [High Fidelity Photo in Full Tone](#high-fidelity-photo-in-full-tone)). ## Collapsed loops keep few segments A small closed loop (or a piece that returns to its own junction) whose fit collapsed to a single cubic cannot stay as one, so it kept every positioned point as a straight segment. A looser Paths @@ -250,36 +251,8 @@ Every built-in preset other than Auto Color and Flat Logo traces at Paths 50. Co The palettes, color counts, thresholds and other options of the presets did not change. The enhanced versions of these presets use the same Paths, Corners and Noise. 6 Colors and 16 Colors were at Noise 15 and Black and White Logo at 25 until [Noise joins the nearest color](#noise-joins-the-nearest-color); -the measurements below were made at those values. - -High Fidelity Photo later moved to Palette › Full Tone at Color detail 85 and Method › Abutting (it was a -Limited palette of 64 colors, Overlapping); Paths, Corners and Noise stay 50, 50 and 5. These are -VectorCraft's own values. Palette › Full Tone splits its colors until none spans more than its width -limit, then, while it has fewer colors than Color detail's value (85 at 85), splits the narrower ones -too, where the image has that many colors; the colors that look alike then merge, so a trace can end -with fewer. Automatic's continuous-tone colors do not take that count. Full Tone's colors merge as one -color when they are thoroughly mixed and less than 5 apart in Oklab × 100, or mixed in patches -(compression blocks) and less than 1.5 apart; the other palettes, Automatic included, keep the RGB test -(under 30 levels and thoroughly mixed, or under 12 and mixed in patches). These rules apply to every -trace with Palette › Full Tone, so an existing Full Tone trace or saved preset traces differently when -it is traced again. - -On 19 photos, cartoons and synthetic shapes of 400 to 4,000 px, the mean pixel difference summed over the -inputs fell from 80.5 to 65.6 levels. It fell by more than 1% on 14 inputs (2.88 to 2.19 and 2.59 to 2.48 -on two photos, the second a JPEG at quality 40; 1.88 to 1.45 on a 4000 × 3000 photo; 12.40 to 7.44 on an -upscaled cartoon) and changed by less than 1% on the other 5. Anchors rose 1.66 times (1.98 million to -3.29 million), the SVG size 1.31 times, and the trace time 1.9 times (14.1 to 27.1 s for all 19, 3 at a -time). Flat synthetic art costs the most: 12 to 400 anchors on a 4000 × 3000 image of two flat colors, and -about 3 times the anchors on two images of synthetic shapes (400 × 300 and 1600 × 1200), with the same -pixel difference. Peak memory fell on every input in the same pass: -942 to 626 MiB on a 1536 × 2048 cartoon. Low Fidelity Photo, 16 Colors, 6 Colors, Black and White Logo -and Auto Color give byte-identical SVGs. On three flat colors stored in 8 × 8 blocks, each block off by -up to 8 levels a channel, High Fidelity Photo traces 3 colors as 3 paths; without the patch rule it traced -7 colors as 74 paths. Tests: `high_fidelity_photo_traces_in_full_tone`, -`full_tone_keeps_a_noisy_ramps_neighboring_tones` and `full_tone_merges_a_flat_colors_compression_blocks` -in `crates/trace/src/tests.rs`, `full_tone_merges_only_mixed_colors_that_look_alike` in -`crates/trace/src/quantize.rs`, and `full_tone_makes_one_color_per_step_of_color_detail` in -`crates/trace/src/quantize/palette.rs`. +the measurements below were made at those values. High Fidelity Photo's palette and Method changed +later (see [High Fidelity Photo in Full Tone](#high-fidelity-photo-in-full-tone)). Measured with the harness below (section 1, each preset on the inputs it is meant for), before and after: anchors fall in 10 of the 12 changed presets, for example 5,494 to 3,136 (High Fidelity Photo), 33 to 27 @@ -300,6 +273,47 @@ the other sections of this file, and in the Image Trace entries of [target-app-parity.md](target-app-parity.md), were measured at the earlier values. Test: `presets_have_their_paths_corners_and_noise` in `crates/trace/src/tests.rs`. +## High Fidelity Photo in Full Tone +High Fidelity Photo traces with Palette › Full Tone at Color detail 85 and Method › Abutting. It traced +with a Limited palette of 64 colors, Overlapping, before. Paths, Corners and Noise stay 50, 50 and 5. +These are VectorCraft's own values. Low Fidelity Photo keeps its Limited palette of 20 colors. + +Palette › Full Tone splits its colors until none spans more than its width limit. Then, while it has +fewer colors than Color detail's value (85 at 85), it splits the narrower ones too, where the image has +that many colors. The colors that look alike merge after that, and a merged color can merge again, so a +trace can end with far fewer colors than that count: a gray-to-green ramp 256 px wide with up to 8 levels +of grain a channel ends with 6 colors at Color detail 85, where the RGB test leaves 4. Full Tone's colors +merge when they are thoroughly mixed and less than 5 apart in Oklab × 100, or mixed in patches +(compression blocks) and less than 1.5 apart. The other palettes, Automatic included, keep the RGB test +(under 30 levels and thoroughly mixed, or under 12 and mixed in patches), and Automatic's continuous-tone +colors do not take the least count. These rules apply to every trace with Palette › Full Tone, so an +existing Full Tone trace or saved preset traces differently when it is traced again. + +On 19 photos, cartoons and synthetic shapes of 400 to 4,000 px, the mean pixel difference summed over the +inputs fell from 80.5 to 65.6 levels. It fell by more than 1% on 14 inputs (2.88 to 2.19 and 2.59 to 2.48 +on two photos, the second a JPEG at quality 40; 1.88 to 1.45 on a 4000 × 3000 photo; 12.40 to 7.44 on an +upscaled cartoon) and changed by less than 1% on the other 5. Anchors rose 1.66 times (1.98 million to +3.29 million) and the SVG size 1.31 times. The trace time rose 1.7 times (18.9 to 31.5 s for all 19, with +both builds tracing 3 images at a time in the same run). Flat synthetic art costs the most: 12 to 400 +anchors on a 4000 × 3000 image of two flat colors, and about 3 times the anchors on two images of +synthetic shapes (400 × 300 and 1600 × 1200), with the same pixel difference. A flat gray 192 × 128 with +up to 3 levels of grain a channel traces as 25 colors and 244 anchors, where the Limited palette of 64 +traced 1 color and 4 anchors; with up to 5 or 8 levels both trace it as 25 to 37 colors, on each of the +grays tested (28, 60, 128 and 200). + +In the same run, peak memory fell on 16 of the 19 inputs, for example 906 to 625 MiB on a 1536 × 2048 +cartoon, and rose on 3 small ones (by 5 to 11 MiB). Abutting accounts for the fall: the earlier preset +with Method › Abutting peaked at 523 MiB on the same cartoon, against 924 MiB with Overlapping, in another +run. Low Fidelity Photo, 16 Colors, 6 Colors, Black and White Logo and Auto Color give byte-identical +SVGs. On three flat colors stored in 8 × 8 blocks, each block off by up to 8 levels a channel, High +Fidelity Photo traces 3 colors as 3 paths; without the patch rule it traced 7 colors as 74 paths. + +Tests: `high_fidelity_photo_traces_in_full_tone`, `full_tone_keeps_more_of_a_noisy_ramps_tones`, +`full_tone_traces_a_noisy_dark_ground_like_a_light_one` and +`full_tone_merges_a_flat_colors_compression_blocks` in `crates/trace/src/tests.rs`, +`full_tone_merges_only_mixed_colors_that_look_alike` in `crates/trace/src/quantize.rs`, and +`full_tone_makes_one_color_per_step_of_color_detail` in `crates/trace/src/quantize/palette.rs`. + ## 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 diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 2e88552340..4e3ef4875b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1584,7 +1584,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **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, blurred edges:** in Color with a Limited palette of at most 16 colors (3 Colors, 6 Colors, 16 Colors) and in Grayscale with at most 16 grays (Shades of Gray), by VectorCraft's own rule (RGB distances, 0 to 255 a channel), a blend pixel with no unblended pixel of its own color within 4 pixels takes the nearer side of the pair of colors within 8 pixels that it is best a blend of, of the 8 colors within 8 pixels nearest to its color, when that pair explains it twice as well as its own color, or when it lies between the two and off the line between them by less than 0.15 of their distance apart; it keeps its color when it is one of the pair. Grayscale compares lightness. The in-between tones of an edge blurred over several pixels no longer trace as rings around it. High Fidelity Photo, Low Fidelity Photo and Black and White trace as before, and so do Automatic, Full Tone and Document Library palettes. Noisy and textured images settle more of their pixels. By `crates/trace/tests/quality` (256 px variants), 16 Colors on blurred flat art went from 9.0 paths to 3.0, 158 anchors to 34 and 0.239 px off to 0.069, and 6 Colors from 6.0 paths to 3.0 and 0.226 px off to 0.071; askew shapes take up to 11 px more area in colors the art does not have, and with 16 Colors the largest distance from a thin line's outline to the trace goes from 23.5 px to 45.3 (see [quality notes](image-trace-quality.md#blurred-edges)). Code-drawn blurred-disc and grayscale ramp tests in `crates/trace`. - **Image Trace, preset Paths, Corners and Noise:** every built-in preset but Auto Color and Flat Logo traces at Paths 50, and so do their enhanced versions; among those presets, Corners is 100 in Technical Drawing, 75 in Default, Black and White Logo, Line Art and Outline and 50 in the other eight, and Noise is 1 to 90 px by preset. Palettes and color counts are unchanged. Figures for these presets in the other Image Trace entries were measured at the earlier values. By `crates/trace/tests/quality`, High Fidelity Photo goes from 5,494 anchors to 3,136 and Black and White Logo from 27 to 14, while 16 Colors on flat art goes from 0.100 px off to 0.123 (see [quality notes](image-trace-quality.md#preset-paths-corners-and-noise)). Test `presets_have_their_paths_corners_and_noise` in `crates/trace`. -- **Image Trace, High Fidelity Photo in Full Tone:** High Fidelity Photo traces with Palette › Full Tone at Color detail 85 and Method › Abutting (VectorCraft's own values; it was a Limited palette of 64 colors, Overlapping). Palette › Full Tone splits into at least one color per step of Color detail where the image has that many, and its colors merge only when they look alike (less than 5 apart in Oklab × 100 and thoroughly mixed, or less than 1.5 and mixed in patches); this applies to every Full Tone trace. On 19 test images the summed mean pixel difference fell from 80.5 to 65.6 levels, with 1.66 times the anchors and 1.9 times the trace time (see [quality notes](image-trace-quality.md#preset-paths-corners-and-noise)). Tests in `crates/trace`. +- **Image Trace, High Fidelity Photo in Full Tone:** High Fidelity Photo traces with Palette › Full Tone at Color detail 85 and Method › Abutting (VectorCraft's own values; it was a Limited palette of 64 colors, Overlapping). Palette › Full Tone splits into at least one color per step of Color detail where the image has that many, and then merges the colors that look alike (less than 5 apart in Oklab × 100 and thoroughly mixed, or less than 1.5 and mixed in patches), which can leave far fewer; this applies to every Full Tone trace. On 19 test images the summed mean pixel difference fell from 80.5 to 65.6 levels, with 1.66 times the anchors and 1.7 times the trace time (see [quality notes](image-trace-quality.md#high-fidelity-photo-in-full-tone)). Tests in `crates/trace`. - **Image Trace, Noise joins the nearest color:** in Color and Grayscale, a region below Noise whose longest-border color is 10 or more apart from its own (Oklab × 100) joins the neighboring color nearest the average of its pixels (leaving out cut-edge pixels that are the color beside them blended with the transparent background), among those sharing at least a tenth of that border, so thin dark lines no longer break into dashes; a single pixel tied between colors joins by border (VectorCraft's own rule and values). 6 Colors and 16 Colors use Noise 8 and Black and White Logo Noise 5. On three illustrations with fine dark lines the mean difference falls 29% to 42% (16 Colors) with 72% to 99% more anchors (see [quality notes](image-trace-quality.md#noise-joins-the-nearest-color)). Tests in `crates/trace/src/quantize/denoise.rs`. Scores and hours unchanged. - **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)). - **Image Trace, measured:** `crates/trace/tests/quality` traces drawings made from known vector art with every preset and [`image-trace-quality.md`](image-trace-quality.md) records the numbers against the baseline. Black and White, Grayscale and Color place each edge by the blend of the pixels across it (to a fraction of a pixel on anti-aliased and blurred images; hard-edged images are read as staircases) and fit outlines as Flat Logo does. *Measured* on each preset's own inputs, all sizes and variants: Default's outlines went from 0.31 px off on average to 0.09 (largest 1.51 to 1.02), Black and White Logo's from 0.27 to 0.06 with 0.3 kinks per trace where it had 15, and the gaps between abutting paths from 64 px to 22. On clean curved shapes Black and White Logo is 0.02 px off (the open tracer measured beside it: 0.20). The palette is made of the picture's own colours (blends along edges take none of it, colours that noise made of one colour merge, a blend pixel goes to one of the two colours it lies between; #1504): 16 Colors on flat art, all variants, went from 70 paths to 4.2 and from 5.1 px off to 0.13, with no path left in a colour the art doesn't have (5.9 before). Photos are smoothed within their tones before they are quantised and stacked layers go by lightness (#1516): High Fidelity Photo went from 3,653 paths to 121 with its colour error down from 2.30 to 1.75, and a 16 megapixel photo-like image is traced in 3.5 s where 4 megapixels were refused. Since then, by the same harness: outlines are cut at their junctions and each shared piece is fitted once (#1535: gaps and overlaps between abutting paths 22 to 50 px of area down to under 2); layers are traced within the box of their pixels and a few at a time (#1546: a 16 megapixel photo 3.9 GB to 0.9 GB); black and white are read against the image's own black and the paper near each edge (#1563, for thin lines in blurred and scanned art); Ignore Color and the Auto Color and Outline presets (#1574); Snap Curves To Lines levels lines within 2.5 degrees of level or upright (#1593, the angle our choice); Create: Strokes puts centre lines in the middle of their ink and makes them as wide as it (#1595: Outline 0.295 to 0.052 px from the true centre line, 18.4 to 2.7 anchors a stroke); sharp corners whose pixel is mostly outside the shape stay corners (#1609: Default 69% to 76% kept). Three options, each off unless asked for as the legacy presets have them: Shapes (#1609: 57 to 62% of plain circles, ellipses, rectangles and regular polygons come out as live shapes, rounded rectangles rarely), Auto Grouping (#1618: paths grouped with what lies inside them, the same picture) and Gradients (#1627: linear gradients traced as one gradient-filled path; on gradient inputs 6 Colors' colour error 2.12 to 0.62 with 6.4 to 3.4 paths, none found in flat art). Snap Curves To Lines moves no end of a line by more than 1.6 px, so long lines a degree or two off stay as the image has them (#1647: Technical Drawing's largest distance 4.21 px to 1.46). Flat Logo takes the tones a scan's uneven paper makes of one colour for one colour (#1657: on scans 470 paths and 21 px off to 8.5 paths and 0.09 px). Shapes finds rounded rectangles and shapes in aliased, blurred and scanned art (#1845: 57 to 62% of the plain shapes up to 98 to 100%, no false shape but one line 2 px wide). Stroked lines get square caps where their ink is cut square, and a wide end that turned towards a corner goes back on its line (#1846: Outline's largest distance 2.94 px to 0.88, 14 anchors to 10). Each of the 14 documented presets has an enhanced version with Auto Grouping and, in all but High Fidelity Photo, Shapes (#1847), measured beside its preset: equal or better within 0.005 px and 1% of edge ΔE on every preset's own inputs (Default 0.091 to 0.083 px); Auto Grouping keeps traced order in its groups, which removed a light seam along the counters of letters. Gradients grows a gradient over the pixels noise and soft rims took off it (#1848: blurred and noisy linear gradients 3 to 11 paths beside the gradient down to 0.5 with 6 Colors, 24 to 56 down to 0.5 to 1.5 with High Fidelity Photo). Silhouettes is 0.52 px off because its threshold is 200 (0.11 px at 128). Still weak, by the same numbers: rounded rectangles and other line-and-arc outlines take 12 to 16 anchors (the fitter does not split lines from arcs), blurred and scanned polygons lose corners, hairlines under half a pixel are lost to the threshold, aliased art is about 0.25 px off, a scan's uneven paper splits into tones when more colours are asked for than the art has, stroke junctions stay at their skeleton pixels, a three-stop gradient in a small or scanned disc is not found, radial gradients stay bands (a draft, #1849, traces them; the documented option is for linear ones, so it waits for a decision), near-regular polygons a few dozen pixels across are made regular with Shapes (up to 0.5 px off), and aliased stroked lines are 0.8 px off at worst.