Iterative image reconstruction using random cubic bézier strokes

原始链接: https://tangled.org/luthenwald.tngl.sh/splined

## Splined:基于贝塞尔曲线的迭代图像重建 Splined 是一款 Metal 加速工具,用于使用随机三次贝塞尔曲线重建图像。它通过采样曲线、栅格化并仅接受那些*减少*图像误差(在 Oklab 色彩空间中衡量)的曲线,迭代地构建图像。 用户提供输入图像(文件或目录),并可以使用诸如最大笔画数、批处理大小、随机种子和输出设置等参数自定义过程。一个关键特性是使用 `--nth` 标志保存中间帧以进行动画。 该算法从初始化为输入图像平均颜色(或用户定义的背景色)的画布开始,并持续进行,直到达到所需的笔画数或重建收敛。Splined 受 “Geometrize” 应用的启发,未来的开发目标是改进抗锯齿效果并支持其他 GPU 后端,例如 WebAssembly。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 使用随机三次贝塞尔曲线笔画的迭代图像重建 (tangled.org) 7点 由 luthenwald 2小时前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

iterative image reconstruction using random cubic bézier strokes, accelerated on metal

showcase#

NOTE

images used here are all under open access by The Met

same input & different seeds → different reconstructions → simple animation:

build#

cargo build -r

usage#

splined: iterative image reconstruction with random cubic bézier strokes (metal-accelerated)

usage: splined <input> [args]

args:
   -n, --number                 <u32>         max splines to draw (default: (w*h)^0.7)
   -b, --batch                  <u32>         batch size per gpu step (default: 32)
   -s, --seed                   <u64>         rng seed (default: 0)
       --max-gpu                <f32>         max gpu usage in (0, 1] (default: 1.0)
   -l, --log                    <0..3>        logging level (default: 1)
   -o, --output                 <path>        output file or dir (default: output.png)
   -c, --current                <path>        current canvas image to resume from (single-file only)
       --nth                    <u32>         save every nth accepted stroke (uses -o as dir)
       --bg                     <avg|r,g,b>   initial canvas color (default: avg)
   -a, --alpha                  <f32>         stroke alpha in [0, 1] (default: 1)
       --min-accept-ratio       <f32>         stagnant if accepted < batch*ratio (default: 0.02)
       --max-stagnant-batches   <u32>         stop after this many stagnant batches (default: 10)

input:
   - file: writes one image to -o/--output (default: output.png)
   - dir:  -o/--output must be a dir; mirrors input tree under it
   - --nth: saves frames to output dir every nth accepted stroke; also writes final.png

examples:
   splined in.png -o out.png
   splined in.png -n 5000 -b 64 -s 42 -o out.png
   splined in.png --nth 50 -o frames/
   splined images/ -o results/ -n 5000 -b 64 -s 42 --nth 50

algorithm#

  • convert input to oklab color space
  • initialize canvas to image average (or --bg)
  • repeat until target stroke count or convergence:
    • sample batch of random cubic béziers (4 control points, uniform over image)
    • rasterize each curve to coverage mask
    • set stroke color to coverage-weighted mean of target pixels
    • accept curves that strictly reduce squared oklab error (Δε² < 0)
    • commit accepted strokes to canvas
  • export final canvas

reference#

  • Geometrize: a desktop app that geometrizes images into geometric primitives

todo#

  • (better) antialiasing algorithm for drawing cubic bézier strokes
  • support other gpu backends (e.g., wasm)
联系我们 contact @ memedata.com