惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
量子位
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Google DeepMind News
Google DeepMind News
小众软件
小众软件
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell

Martin Owens activity

Martin Owens deleted project branch average-color-divide at Inkscape / inkscape Fix divide-by-zero crash when using calligraphy tool (d34276f8) · Commits · Inkscape / inkscape · GitLab Fix divide-by-zero crash when using calligraphy tool (!7923) · Merge requests · Inkscape / inkscape · GitLab Add selection file to bypass Windows command length limits (correction) (865df7a5) · Commits · Inkscape / inkscape · GitLab Draft: Fix AppImage crashing during save on older distros (!7922) · Merge requests · Inkscape / inkscape · GitLab e71fa7f8e0858aab87b7fc0814a30a8c88da9b43 to fe225a6b9e1042c7221d95173be22a02b3725337 · Martin Owens / inkscape · GitLab 403 Forbidden on Inkscape web server (#693) · Issues · Inkscape / inkscape-web · GitLab 403 Forbidden on Inkscape web server (#13509) · Issues · Inkscape / Inbox · GitLab Add selection file to bypass Windows command length limits (correction) (!7917) · 合并请求 · Inkscape / inkscape · GitLab Non-vertical axonometric axis implementation (!7912) · Merge requests · Inkscape / inkscape · GitLab Update split mode on tab switch (!7915) · Merge requests · Inkscape / inkscape · GitLab inset/offset as app functions so they can be used from CLI (!7914) · Merge requests · Inkscape / inkscape · GitLab Performace regresion in last month (#5879) · Issues · Inkscape / inkscape · GitLab [Regression] Right-aligned text has a new gap in 1.4.4 (#6130) · Issues · Inkscape / inkscape · GitLab [Regression] Right-aligned text has a new gap in 1.4.4 (#13498) · Issues · Inkscape / Inbox · GitLab c503804e014994d611de1b225bee8158c06448a8 to a4588d8ead1e7049b90c5a126962746ed286ab17 · Inkscape / inkscape-web · GitLab Validate the extensions of signature file uploads (a4588d8e) · 提交 · Inkscape / inkscape-web · GitLab Allow color conversions using static arrays instead of just vectors (e71fa7f8) · 提交 · Martin Owens / inkscape · GitLab Speed up ungroup on thousands of items (!7908) · Merge requests · Inkscape / inkscape · GitLab Incorrect handling of FontMatrix and transformation matrices with internal PDF import (#4845) · Issues · Inkscape / inkscape · GitLab Handling edge case of negative fonts in PDF (59040229) · 提交 · Inkscape / inkscape · GitLab Handling edge case of negative fonts in PDF (!7911) · 合并请求 · Inkscape / inkscape · GitLab Allow color conversions using static arrays instead of just vectors (33e65d1b) · Commits · Martin Owens / inkscape · GitLab Allow color conversions using static arrays instead of just vectors (9be5f867) · Commits · Martin Owens / inkscape · GitLab a9672ea1dff483b5b3aa8c6b5d88cd223001bef5 to 512a5e57602ac52e1d35782a7dcebae04262b2b8 · Martin Owens / inkscape · GitLab Add selection file to bypass Windows command length limits (!7905) · 合并请求 · Inkscape / inkscape · GitLab Revert Pango label changes (1.4.x) (!7907) · 合并请求 · Inkscape / inkscape · GitLab Crash on selecting a `<text>` object without a `<tspan>` inside (#5462) · Issues · Inkscape / inkscape · GitLab Fix breakage with Ubuntu 26.04 CI (!7904) · 合并请求 · Inkscape / inkscape · GitLab c673fdd5148253276826d4eda3951daaefb82607 to 356b31383ba324396a225686613236484305533d · Martin Owens / inkscape · GitLab
Add custom color palette support to bitmap tracing with n...
2026-04-14 · via Martin Owens activity

Add custom color palette support to bitmap tracing with novel color quantization algorithm

  • Review changes

  • Download

NOTE: This PR has been co-authored by Claude.ai. I could not find the official policy of Inkscape regarding AI contributions. Please discard this PR if it contravenes Inkscape policies. The code has been checked and tested by myself (in addition to running ninja check).


Allow users to define their own color palette (or modify the auto-generated one) for multi-color tracing (Trace Bitmap > Multicolor > Colors), instead of relying solely on automatic octree color quantization.

This addresses a pain point when vectorizing a bitmap and getting a lot of similar colors, missing important hues present in the image.

When "Colors" mode is selected in the Multicolor tab, a palette editor replaces the scans slider. The palette is automatically populated by analyzing the selected image (sampling 10K pixels out of the image, so that it remains always reponsive). The optimal number of colors and their values are determined without user interaction.

Each color is shown as a row with:

  • A color swatch: hover to see the eyedropper icon, click to pick a color directly from the canvas (reuses the dropper tool's one-time pick mechanism, same as Fill & Stroke)
  • A hex label with disclosure arrow: click to expand an inline color picker with HSL/RGB sliders (reuses ColorPickerPanel, the same widget as Fill & Stroke)
  • A delete button to remove individual colors

The "+" button uses constrained k-means to find the best next color to add (the most distinctive color not yet covered by the palette). The refresh button re-extracts the optimal palette from the image.

The custom palette is then passed through to the tracing engine, which maps each pixel to the nearest palette color instead of running octree quantization. The rest of the tracing pipeline (per-color mask creation, potrace vectorization, stacking) works unchanged.

The attached SVG shows the old vs new color quantization algorithm on a range of different bitmap types: samples_tracing_autopalette.svg

Perceptual color quantization

The previous octree quantization operated in raw RGB space and allocated colors proportionally to pixel count: a large gray background would consume most of the palette while small vivid regions (e.g. colored flowers) were lost.

The new approach uses saliency-weighted k-means in Oklab perceptual color space:

  1. Oklab color space: Euclidean distance in Oklab closely matches perceived color difference, so the algorithm naturally preserves hue diversity rather than clustering around brightness variations.
  2. Local chroma saliency weighting: Before running k-means, each pixel is weighted by how much its chroma differs from its local neighborhood. Pixels at color boundaries and in small distinctive regions get ~20× more influence than uniform background pixels. This steers k-means toward visually important colors without sacrificing clustering quality.
  3. Automatic palette size: The elbow method on k-means inertia determines the optimal number of colors (2–10), biased slightly toward richer palettes.
  4. Pixel-to-palette assignment also uses Oklab distance, so each pixel maps to the color that looks closest, not just the geometrically nearest in RGB.

The old octree quantization is preserved for QUANT_MONO and BRIGHTNESS_MULTI modes where the output is converted to grayscale anyway.

Implementation notes

  • Oklab conversion is implemented directly in quantize.cpp rather than reusing ok_color::linear_srgb_to_oklab() from src/colors/spaces/ok-color.cpp, because those functions are internal to the color picker widget (not declared in the public header), use different types, and operate on linear sRGB without handling the transfer function. A self-contained implementation avoids coupling between unrelated subsystems.
  • Palette swatches use GtkSnapshot (snapshot_vfunc with gtk_snapshot_append_color) instead of Cairo, following the approach established in !7765 (merged).
  • The inline color picker uses a shared ColorPickerPanel instance (with PlateType::None) that is inserted below the active row and bound to its ColorSet, ensuring full UI consistency with Fill & Stroke.
Edited by Séverin Lemaignan