A neural-network-based image vectorizer that "paints" an image using differentiable Bezier strokes. Instead of traditional edge detection, it uses gradient descent to optimize the position, color, and opacity of each stroke to match a target image.
- Differentiable Rendering: Uses PyTorch to backpropagate through the rendering process.
- Bezier Strokes: Each stroke is defined by a quadratic Bezier curve.
- Painter's Algorithm: Layers strokes with alpha blending for complex compositions.
- Hardware Acceleration: Supports CUDA (NVIDIA), DirectML (AMD), and CPU.
- Sparsity Regularization: Encourages the model to use fewer, more meaningful strokes.
-
Clone the repository:
git clone https://github.com/mcarbonell/vectorizer-ai.git cd vectorizer-ai -
Install dependencies:
pip install -r requirements.txt
-
(Optional) For AMD GPU acceleration on Windows:
pip install torch-directml
Simply run the main script to see it in action with a sample image from CIFAR-10:
python vectorizer.pyResults will be saved in the results/figures/ directory.
- Initialization: Start with a set of random Bezier curves on a blank canvas.
- Rendering: For each pixel, calculate the distance to the nearest curve to create a stroke mask.
- Compositing: Blend the strokes using the standard alpha-compositing formula (Painter's Algorithm).
- Optimization: Compare the generated image with the target using Mean Squared Error (MSE).
- Backpropagation: Adjust the stroke parameters (points, colors, alpha) to minimize the error.
This project is licensed under the MIT License - see the LICENSE file for details.
