A Rust-based tool uses random cubic Bézier curves and GPU acceleration to progressively reconstruct images through iterative error minimization, offering a unique approach to geometric image approximation.
The project splined presents an intriguing alternative to conventional image processing techniques. Rather than working with pixels directly, it employs an iterative algorithm that builds an image from scratch using random cubic Bézier curves, accelerated via Apple's Metal API. The core premise is simple yet powerful: start with a blank canvas, generate random curves, and only commit those that reduce the overall error compared to the target image. This process repeats until a target stroke count or convergence criterion is met.
The algorithm operates in the Oklab color space, which provides perceptually uniform color differences. For each iteration, the tool samples a batch of random cubic Bézier curves—defined by four control points uniformly distributed across the image. Each curve is rasterized to create a coverage mask, and the stroke's color is set to the coverage-weighted mean of the corresponding target pixels. The key decision point is acceptance: a curve is only committed to the canvas if it strictly reduces the squared Oklab error (Δε² < 0). This greedy, error-minimizing approach ensures that each stroke improves the reconstruction.
The implementation is written in Rust and leverages Metal for GPU acceleration, making it particularly efficient on Apple silicon. The command-line interface offers extensive configuration, including parameters for the maximum number of splines, batch size per GPU step, random seed, and GPU usage limits. Users can also control the initial canvas color, stroke transparency, and convergence criteria. For instance, the --min-accept-ratio and --max-stagnant-batches parameters allow the algorithm to halt when progress stalls, preventing unnecessary computation.
A notable feature is the ability to generate animations by saving every nth accepted stroke. This creates a visual record of the reconstruction process, showing how the image emerges from the accumulation of curves. The tool supports both single-image processing and batch operations on directories, making it versatile for different workflows.
From a technical perspective, the use of cubic Bézier curves is interesting. Unlike simpler primitives like lines or circles, Bézier curves offer smooth, flexible shapes that can approximate complex contours. However, this flexibility comes with computational cost—rasterizing curves is more intensive than drawing simple shapes. The Metal acceleration mitigates this, but the algorithm's efficiency still depends heavily on the batch size and the acceptance rate of curves.
The project's README mentions Geometrize as a related tool, which is a desktop application that converts images into geometric primitives. While Geometrize focuses on creating stylized representations using shapes like triangles or circles, splined takes a more procedural, iterative approach. The author notes that a better antialiasing algorithm for drawing cubic Bézier strokes is a future todo, which would improve visual quality, especially for fine details.
Another planned improvement is support for other GPU backends, such as WebAssembly (WASM). This would enable running splined in web browsers, expanding its accessibility beyond macOS. The current Metal-only limitation means the tool is tied to Apple hardware, but a WASM port could democratize access to this unique reconstruction method.
The implications of this approach extend beyond mere image approximation. It demonstrates how iterative, error-driven algorithms can produce visually compelling results, even with simple primitives. The method also highlights the trade-off between computational complexity and visual fidelity. While the output may not be photorealistic, it captures the essence of the target image in a stylized, abstract manner—useful for artistic applications or as a foundation for further processing.
Critically, the algorithm's greedy nature means it may not find a globally optimal solution. By accepting curves that immediately reduce error, it might miss combinations of strokes that yield better results in the long run. This is a common challenge in iterative optimization, and exploring alternative acceptance criteria or incorporating look-ahead strategies could be an interesting research direction.
In summary, splined offers a novel perspective on image reconstruction, blending mathematical elegance with practical GPU acceleration. Its iterative, stroke-based approach provides a tangible demonstration of how complex images can emerge from simple, repeated operations—a concept that resonates with broader themes in computational creativity and procedural generation. As the project evolves, improvements in antialiasing and multi-backend support will likely broaden its appeal and utility.

Comments
Please log in or register to join the discussion