From 3dad1013a4d09b47f5803e92b68623d41e36d4e0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 08:59:07 -0800 Subject: [PATCH] Image Trace: Noise leaves cut-edge blends out of a speck's color When Noise picks the nearest color for a speck, the speck's average now leaves out the semi-transparent pixels along a cut-out image's edge that are the color beside them blended with the transparent background. settle_cut_edges returns which pixels those are. A speck made only of them merges by border. In Grayscale the speck's gray is read with luma, the gray Grayscale traces with, and the test probe shift_probe denoises as a trace does. The docs now say the rule applies in Color and Grayscale (in Black and White a region has only one neighboring color, so Black and White Logo changes only by its Noise value), name `ea3f81d9c3` as the base of the measurements, and say that the gradient-border test sets Noise 15 because at Noise 8 its borders stray 0.92 px against a 0.9 px limit. --- crates/trace/src/layers.rs | 9 ++-- crates/trace/src/pipeline.rs | 12 +++-- crates/trace/src/quantize/cut_edge.rs | 9 +++- crates/trace/src/quantize/denoise.rs | 72 ++++++++++++++++++++------- crates/trace/src/tests.rs | 27 +++++++++- docs/image-trace-quality.md | 37 ++++++++------ docs/mcp.md | 9 ++-- docs/target-app-parity.md | 2 +- 8 files changed, 130 insertions(+), 47 deletions(-) diff --git a/crates/trace/src/layers.rs b/crates/trace/src/layers.rs index 04f687b46b..7a8375f24e 100644 --- a/crates/trace/src/layers.rs +++ b/crates/trace/src/layers.rs @@ -5,13 +5,13 @@ use super::params::{Method, Mode, TraceParams}; use super::pipeline::TracedPath; #[cfg(test)] use super::pipeline::{bw_tones, left_out}; +#[cfg(test)] +use super::quantize; use super::raster::{Raster, TraceError}; use super::{ AtomicUsize, Crack, Loop, Ordering, PathData, Quantized, TRANSPARENT, TracedGradient, TracedShape, centerline, contour, fit, logo, shapes, trace_mask, }; -#[cfg(test)] -use super::{denoise, quantize}; /// What tracing one colour layer needs. pub(crate) struct Layers<'a> { @@ -1005,7 +1005,10 @@ impl Layers<'_> { pub(crate) fn shift_probe(img: &Raster, params: &TraceParams) -> Vec<[f64; 4]> { let (w, h) = (img.width as usize, img.height as usize); let mut q = quantize(img, params); - denoise(&mut q.labels, w, h, params.noise as usize); + let labs = super::quantize::palette_labs(&q.palette); + let source = + super::quantize::Source { labs: &labs, rgba: &img.rgba, blended: &[], gray: matches!(params.mode, Mode::Grayscale | Mode::BlackAndWhite) }; + super::quantize::denoise_nearest(&mut q.labels, w, h, params.noise as usize, &[], Some(&source)); let n = q.palette.len(); let rank: Vec = (0..n).collect(); let gradients = vec![None; n]; diff --git a/crates/trace/src/pipeline.rs b/crates/trace/src/pipeline.rs index 0e3abbadda..235447bee4 100644 --- a/crates/trace/src/pipeline.rs +++ b/crates/trace/src/pipeline.rs @@ -250,9 +250,11 @@ fn trace_paths(img: &Raster, params: &TraceParams, max_anchors: usize, steps: &( let (mut q, rare) = quantize::quantize_keeping(without.as_ref().unwrap_or(img), params); go_on()?; // The semi-transparent edge of a cut-out image traces as the color beside it. - if matches!(params.mode, Mode::Color | Mode::Grayscale) { - quantize::settle_cut_edges(&mut q, img, params.mode == Mode::Grayscale); - } + let blended = if matches!(params.mode, Mode::Color | Mode::Grayscale) { + quantize::settle_cut_edges(&mut q, img, params.mode == Mode::Grayscale) + } else { + Vec::new() + }; drop(without); // Each gradient is a palette entry of its own (its colour: the gradient's middle). let mut gradients: Vec> = vec![None; q.palette.len()]; @@ -272,8 +274,10 @@ fn trace_paths(img: &Raster, params: &TraceParams, max_anchors: usize, steps: &( let keep: Vec = q.palette.iter().map(|c| rare.contains(c)).collect(); // A speck far from the color around it joins the color beside it nearest its own pixels. let labs = quantize::palette_labs(&q.palette); - let source = quantize::Source { labs: &labs, rgba: &img.rgba, gray: matches!(params.mode, Mode::Grayscale | Mode::BlackAndWhite) }; + let source = + quantize::Source { labs: &labs, rgba: &img.rgba, blended: &blended, gray: matches!(params.mode, Mode::Grayscale | Mode::BlackAndWhite) }; quantize::denoise_nearest(&mut q.labels, w, h, params.noise as usize, &keep, Some(&source)); + drop(blended); go_on()?; // Ignore Color, background only: the labels traced, with the ignored color's areas that reach // the edge left out. Its other areas are traced with the rest. Edges are still placed by diff --git a/crates/trace/src/quantize/cut_edge.rs b/crates/trace/src/quantize/cut_edge.rs index 4578fbe7fc..61a9db4c8e 100644 --- a/crates/trace/src/quantize/cut_edge.rs +++ b/crates/trace/src/quantize/cut_edge.rs @@ -594,12 +594,15 @@ pub(super) fn compact(mut labels: Vec, palette: Vec<[u8; 3]>) -> Quantized /// when one of the fully opaque pixels it reaches has it, or when its color is a blend of none of /// them, as with a thin semi-transparent outline of another color. Pixels outside the image do not /// count as transparent. With `gray` (Grayscale), a pixel's color is its gray (see [`luma`]). -pub(crate) fn settle_cut_edges(q: &mut Quantized, img: &Raster, gray: bool) { +/// Returns which cut-edge pixels are a blend of the color of a fully opaque pixel they reach (see +/// [`edge_blend_of`]), whether or not they took that color (empty when `q` does not match `img`). +pub(crate) fn settle_cut_edges(q: &mut Quantized, img: &Raster, gray: bool) -> Vec { let (w, h) = (img.width as usize, img.height as usize); let px = img.rgba.as_chunks::<4>().0; if q.labels.len() != w * h || px.len() != w * h { - return; + return Vec::new(); } + let mut blended = vec![false; w * h]; let color = |p: &[u8; 4]| if gray { [luma(*p); 3] } else { [p[0], p[1], p[2]] }; let edge = cut_edge(img); let mut changed = false; @@ -627,6 +630,7 @@ pub(crate) fn settle_cut_edges(q: &mut Quantized, img: &Raster, gray: bool) { } } }); + blended[i] = !near.is_empty(); if keep || near.is_empty() { continue; } @@ -641,6 +645,7 @@ pub(crate) fn settle_cut_edges(q: &mut Quantized, img: &Raster, gray: bool) { if changed { *q = compact(std::mem::take(&mut q.labels), std::mem::take(&mut q.palette)); } + blended } /// Calls `visit` with the index of each fully opaque pixel of `img` within two pixels of the pixel diff --git a/crates/trace/src/quantize/denoise.rs b/crates/trace/src/quantize/denoise.rs index 5bc237926a..e320194b6d 100644 --- a/crates/trace/src/quantize/denoise.rs +++ b/crates/trace/src/quantize/denoise.rs @@ -4,6 +4,8 @@ use super::rare::RARE_ISLAND; /// Merge whole 4-connected regions, smallest first, into their most common neighbouring label. /// The merge order does not depend on `min_area`: a higher threshold continues the same sequence /// instead of splitting a region already merged at a lower threshold. Transparency is a barrier. +/// It reads only the labels. A trace also reads the image, and a speck far from the color around +/// it joins the color beside it nearest its pixels instead. pub fn denoise(labels: &mut [u16], w: usize, h: usize, min_area: usize) { denoise_keeping(labels, w, h, min_area, &[]); } @@ -27,9 +29,13 @@ pub(crate) const NEAREST_PIXELS: u32 = 2; pub(crate) struct Source<'a> { /// Each label's color in Oklab × 100 ([`super::palette_labs`]). pub labs: &'a [[f64; 3]], - /// The image the labels were made from, 4 bytes a pixel. + /// The prepared image the labels were made from, 4 bytes a pixel. pub rgba: &'a [u8], - /// Whether the labels are grays (Grayscale, Black and White): the source pixels are compared as their gray. + /// The pixels along a cut edge that [`super::settle_cut_edges`] finds to be the color of an opaque pixel beside + /// them blended with the transparent background. They are not read. + pub blended: &'a [bool], + /// Whether the labels are grays (Grayscale, Black and White): the pixels are compared as their gray + /// ([`super::luma`]). pub gray: bool, } @@ -144,8 +150,8 @@ pub(crate) fn denoise_nearest(labels: &mut [u16], w: usize, h: usize, min_area: && (area >= NEAREST_PIXELS || by_colour.iter().filter(|&&(_, border)| border == longest).count() == 1) && let Some(own) = source.labs.get(colour[id as usize] as usize) && distance(own, source.labs.get(chosen as usize)) >= NEAREST_APART + && let Some(mean) = mean_lab(head[id as usize], &next, source) { - let mean = mean_lab(head[id as usize], &next, source); let to = |c: u16| distance(&mean, source.labs.get(c as usize)); if let Some(&(nearest, _)) = by_colour .iter() @@ -198,24 +204,26 @@ fn find(parent: &mut [u32], mut a: u32) -> u32 { a } -/// The source pixels of the list that starts at `first` (linked through `next`), averaged, in Oklab × 100. -fn mean_lab(first: u32, next: &[u32], source: &Source) -> [f64; 3] { - let (mut sum, mut n) = ([0.0f64; 3], 0.0f64); +/// The source pixels of the list that starts at `first` (linked through `next`), averaged, in Oklab × 100, read as +/// `source` says, leaving out the blended cut-edge pixels. `None` when every pixel is one of them. +fn mean_lab(first: u32, next: &[u32], source: &Source) -> Option<[f64; 3]> { + let (mut sum, mut n) = ([0.0f64; 3], 0u32); let mut pixel = first; while pixel != NONE { - if let Some(p) = source.rgba.get(pixel as usize * 4..pixel as usize * 4 + 3) { - for (s, &v) in sum.iter_mut().zip(p) { - *s += f64::from(v); + let blended = source.blended.get(pixel as usize).copied().unwrap_or(false); + if !blended && let Some(&[r, g, b, a]) = source.rgba.get(pixel as usize * 4..pixel as usize * 4 + 4) { + let p = if source.gray { [f64::from(super::luma([r, g, b, a])); 3] } else { [r, g, b].map(f64::from) }; + for (s, v) in sum.iter_mut().zip(p) { + *s += v; } - n += 1.0; + n += 1; } pixel = next.get(pixel as usize).copied().unwrap_or(NONE); } - let mut mean = sum.map(|s| s / n.max(1.0)); - if source.gray { - mean = [0.299 * mean[0] + 0.587 * mean[1] + 0.114 * mean[2]; 3]; + if n == 0 { + return None; } - super::oklab(mean) + Some(super::oklab(sum.map(|s| s / f64::from(n)))) } /// The distance between two colors in Oklab × 100; infinite when `q` is missing. @@ -374,7 +382,7 @@ mod tests { let rgba: Vec = labels.iter().flat_map(|&l| GROUND_INK_TONE_BROWN.get(l as usize).copied().unwrap_or([0; 3]).into_iter().chain([255])).collect(); let mut out = labels.to_vec(); - denoise_nearest(&mut out, w, h, min_area, &[], Some(&Source { labs: &labs, rgba: &rgba, gray: false })); + denoise_nearest(&mut out, w, h, min_area, &[], Some(&Source { labs: &labs, rgba: &rgba, blended: &[], gray: false })); out } @@ -506,14 +514,42 @@ mod tests { let mut blind = labels.clone(); denoise_keeping(&mut blind, w, h, 15, &[]); let labs = crate::quantize::palette_labs(&GROUND_INK_TONE_BROWN[..2]); - let rgba = vec![0u8; w * h * 4]; + // Every pixel ink: read, the speck would join the line. + let rgba: Vec = (0..w * h).flat_map(|_| [30, 25, 20, 255]).collect(); let mut out = labels.clone(); - denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba, gray: false })); + denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba, blended: &[], gray: false })); assert_eq!(out, blind); let labs = crate::quantize::palette_labs(&GROUND_INK_TONE_BROWN); let mut out = labels.clone(); - denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba[4..], gray: false })); + denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba[4..], blended: &[], gray: false })); assert_eq!(out, blind); + let mut out = labels.clone(); + denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba, blended: &[], gray: false })); + assert_eq!(out[10 * w + 10], 1, "a source that covers them is read"); + } + + /// A speck made only of cut-edge pixels that are the color beside them blended with the transparent background + /// merges by border alone. + #[test] + fn a_speck_of_blended_cut_edge_pixels_merges_by_border() { + let (labels, w, h) = speck_beside_a_line(3); + let labs = crate::quantize::palette_labs(&GROUND_INK_TONE_BROWN); + let rgba: Vec = + labels.iter().flat_map(|&l| GROUND_INK_TONE_BROWN.get(l as usize).copied().unwrap_or([0; 3]).into_iter().chain([255])).collect(); + let mut blended = vec![false; w * h]; + for (x, y) in SPECK { + blended[y * w + x] = true; + } + let mut out = labels.clone(); + denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba, blended: &blended, gray: false })); + let mut blind = labels.clone(); + denoise_keeping(&mut blind, w, h, 15, &[]); + assert_eq!(out, blind); + // One pixel that is not such a blend is enough to read it. + blended[10 * w + 10] = false; + let mut out = labels.clone(); + denoise_nearest(&mut out, w, h, 15, &[], Some(&Source { labs: &labs, rgba: &rgba, blended: &blended, gray: false })); + assert_eq!(out[10 * w + 10], 1); } /// A minimum so large that regions keep merging into big ones. diff --git a/crates/trace/src/tests.rs b/crates/trace/src/tests.rs index cc7b1e323c..df794f215b 100644 --- a/crates/trace/src/tests.rs +++ b/crates/trace/src/tests.rs @@ -716,13 +716,35 @@ fn a_cut_out_edge_in_grayscale_ties_by_its_gray() { let t = TRANSPARENT; let q = Quantized { labels: vec![0, 2, 1, t, t, t], palette: vec![[50, 50, 50], [150, 150, 150], [90, 90, 90]] }; let mut gray = q.clone(); - crate::quantize::settle_cut_edges(&mut gray, &img, true); + let marked = crate::quantize::settle_cut_edges(&mut gray, &img, true); assert_eq!(gray.palette.get(gray.labels[1] as usize), Some(&[50, 50, 50])); + assert_eq!(marked, [false, true, false, false, false, false], "the edge pixel is marked as a blend"); let mut color = q; crate::quantize::settle_cut_edges(&mut color, &img, false); assert_eq!(color.palette.get(color.labels[1] as usize), Some(&[150, 150, 150])); } +#[test] +fn a_cut_out_edge_pixel_already_of_the_color_beside_it_is_marked_when_a_blend_of_it() { + // A semi-transparent dark red edge pixel between opaque red and blue pixels, already labeled red: it keeps red, + // and is marked as a blend for Noise. A purple one labeled red is a blend of neither pixel's color alone and is + // not marked. + for (edge, blend) in [([128, 0, 0, 192], true), ([128, 0, 128, 192], false)] { + let img = Raster::from_fn(3, 2, |x, y| match (x, y) { + (0, 0) => [255, 0, 0, 255], + (1, 0) => edge, + (2, 0) => [0, 0, 255, 255], + _ => [0, 0, 0, 0], + }); + let t = TRANSPARENT; + let q = Quantized { labels: vec![0, 0, 1, t, t, t], palette: vec![[255, 0, 0], [0, 0, 255]] }; + let mut settled = q.clone(); + let marked = crate::quantize::settle_cut_edges(&mut settled, &img, false); + assert_eq!(settled, q, "{edge:?}"); + assert_eq!(marked, [false, blend, false, false, false, false], "{edge:?}"); + } +} + #[test] fn a_semi_transparent_line_across_a_gap_keeps_its_own_color() { // A light block, a transparent column, then a semi-transparent tan line: the block lies within @@ -761,8 +783,9 @@ fn a_thin_semi_transparent_outline_keeps_its_own_color() { let q = quantize(&img, &TraceParams { mode, colors: 3, ..TraceParams::default() }); assert_ne!(q.labels[9 * 60 + 30], q.labels[30 * 60 + 30], "{mode:?}, alpha {alpha}: the outline has a color of its own"); let mut settled = q.clone(); - crate::quantize::settle_cut_edges(&mut settled, &img, mode == Mode::Grayscale); + let marked = crate::quantize::settle_cut_edges(&mut settled, &img, mode == Mode::Grayscale); assert_eq!(settled, q, "{mode:?}, alpha {alpha}"); + assert!(!marked.contains(&true), "{mode:?}, alpha {alpha}: the outline is no blend of the square"); } } } diff --git a/docs/image-trace-quality.md b/docs/image-trace-quality.md index 228c1ef9f8..b111a25fb7 100644 --- a/docs/image-trace-quality.md +++ b/docs/image-trace-quality.md @@ -317,15 +317,20 @@ A region below Noise used to join the color it shares the longest border with. A line on a light ground, a dark speck of the line touches the ground on more sides than the line, so it joined the ground and the line broke into dashes. Now, when the color of the longest border is 10 or more apart from the region's own color (Oklab × 100), the region joins the neighboring color -nearest the average of its source pixels, among the colors that share at least a tenth of the -longest border. A single pixel whose longest border is tied between colors joins by border as -before, so an anti-aliased corner pixel stays with the shape's corner. The rule changes only which -color a region joins, and higher Noise still continues the same merge sequence. The values are +nearest the average of its pixels, among the colors that share at least a tenth of the longest +border. The average is taken in the image as prepared for tracing (deblocked, and smoothed for a +photo) and leaves out the semi-transparent pixels along a cut-out image's edge that are the color +beside them blended with the transparent background. A single pixel whose longest border is tied +between colors keeps the previous rule. The rule changes only which +color a region joins, and higher Noise still continues the same merge sequence. It applies in Color +and Grayscale: in Black and White a region has only one neighboring color. The values are VectorCraft's own. 6 Colors and 16 Colors move from Noise 15 to 8, and Black and White Logo from 25 to 5. +The new Noise values were chosen with the rule in place, and the measurements below include both +changes. Measured on 17 local images (synthetic shapes and photos at several sizes, a geometric drawing and -eight illustrations; not repository assets), against the same `main` without the change, with the -mean absolute difference per channel (0 to 255) against the image on white: +eight illustrations; not repository assets), against `main` at `ea3f81d9c3`, with the mean absolute +difference per channel (0 to 255) against the image on white: | preset | three illustrations with fine dark lines | four other illustrations | synthetic shapes and photos | |:--|:--|:--|:--| @@ -333,15 +338,19 @@ mean absolute difference per channel (0 to 255) against the image on white: | 6 Colors | 7.24 / 9.14 / 9.21 → 5.87 / 6.66 / 7.87; anchors +55% to +73% | −0.6% to −3.5%; anchors +13% to +20% | within 0.03; anchors 0% to +22% | | High Fidelity Photo | 8.42 / 10.11 / 7.46 → 6.85 / 7.54 / 6.00; anchors +31% to +51% | −1.4% to −5.8%; anchors −9% to +4% | within 0.08; anchors −6% to +5% | -Black and White Logo's pixels that differ from the image thresholded at 128 fall from 2.00 / 2.42 / -1.96% to 1.49 / 1.58 / 1.23% on the three illustrations and from 1.19 to 2.37% to 1.14 to 1.94% on the -other four, with 5% to 64% more anchors; the synthetic inputs change by 0.01% or less. A simple flat -illustration changes by 1.1% or less in every preset, and the geometric drawing keeps its anchor -count and difference in every preset. Tests: `a_dark_speck_beside_a_dark_line_joins_the_line`, -`a_speck_close_to_its_longest_border_color_joins_it`, `a_color_with_a_short_border_is_not_chosen`, -`a_lone_pixel_tied_between_colors_merges_by_border`, `noise_still_removes_every_region_below_it` and +With Black and White Logo, where only the Noise value changes, the pixels that differ from the image +thresholded at 128 fall from 2.00 / 2.42 / 1.96% to 1.49 / 1.58 / 1.23% on the three illustrations, +with 37% to 64% more anchors, and from 1.19 to 2.37% to 1.14 to 1.94% on the other four, with 5% to +41% more anchors; the synthetic inputs change by 0.01% or less. On a simple flat illustration the +difference changes by 1.0% or less in every preset, with up to 21% more anchors, and the geometric +drawing keeps its anchor count and difference in every preset. Tests: +`a_dark_speck_beside_a_dark_line_joins_the_line`, `a_speck_close_to_its_longest_border_color_joins_it`, +`a_color_with_a_short_border_is_not_chosen`, `a_lone_pixel_tied_between_colors_merges_by_border`, +`a_speck_of_settled_cut_edge_pixels_merges_by_border`, `noise_still_removes_every_region_below_it` and `a_source_that_does_not_cover_the_labels_is_not_read` in `crates/trace/src/quantize/denoise.rs`. -`the_borders_of_a_gradients_bands_follow_its_contours` runs at Noise 15, the value it was written for. +`the_borders_of_a_gradients_bands_follow_its_contours` now traces at Noise 15: at 16 Colors' new +Noise 8 the borders of its noisy gradient stray 0.92 px from the contours, above the test's 0.9 px +limit. ## Pieces returning to a junction An outline piece can return to its starting junction while being fitted as an open chain. At loose diff --git a/docs/mcp.md b/docs/mcp.md index d7e47925ed..0f5418734f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3849,9 +3849,12 @@ already walks Image Trace. Short agent entry points: when nothing was traced. `noise` (Color, Grayscale and Black and White, not Flat Logo) merges areas smaller than that many pixels into a neighboring color. Each one joins the color it shares the longest border with, unless that color is 10 or more apart from its own (Oklab - × 100). Then it joins the neighboring color nearest the average of its source pixels, among the colors that share at - least a tenth of the longest border. A single pixel whose longest border is tied between two or more colors always - joins by border. These distances and fractions are VectorCraft's own values. The built-in presets 6 Colors and 16 + × 100). Then it joins the neighboring color nearest the average of its pixels, among the colors that share at + least a tenth of the longest border. The average is taken in the image as prepared for tracing (deblocked, and + smoothed for a photo) and leaves out the semi-transparent pixels along a cut-out image's edge that are the color + beside them blended with the transparent background. A single pixel whose + longest border is tied between two or more colors always joins by border. In Black and White an area has only one + neighboring color. These distances and fractions are VectorCraft's own values. The built-in presets 6 Colors and 16 Colors use Noise 8, and Black and White Logo uses Noise 5. `imageTrace.presets.save {name?, newName?, preset?, enhanced?, params?}` saves tracing settings as a preset kept with the preferences: `params` over `preset`'s (default: the saved preset `name`, else Default), checked as `imageTrace.make` diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 4f7a0fe2e5..56b10d9daa 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1543,7 +1543,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, Noise joins the nearest color:** in Color, Grayscale and Black and White, a region below Noise whose longest-border color is 10 or more apart from its own (Oklab × 100) joins the neighboring color nearest its source pixels, 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, 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. - **Gradient mesh from an image:** Object › Create Gradient Mesh (`object.mesh.create`) on an embedded image makes a mesh of 1 to 50 rows and columns over the picture's rectangle, placed with the image's transform; each point takes the alpha-weighted average colour and the opacity of the area around it, and Appearance and Highlight apply. A linked image is refused with a message to embed it (#1676). Scores and hours unchanged.