line-drawer recreates a given image by only drawing it by simple straight lines. In the table below you can see the demo image which has been drawn with 10000 lines within 40 seconds, once in the subtractive mode and once in the additive mode.
original image | subtractive mode | additive mode |
--input-path | Input image path. |
--output-path | Output image path. |
--num-lines | Number of lines to draw. |
--line-heaviness | Line heaviness. Integer from 1 to 255, with 255 being completely heavy. |
--num-lines-to-check | Number of lines to check at each iteration. |
--draw-type | Draw types (subtractive/additive). Subtractive means white background with black lines. Additive means black background with with lines. |
--no-random-result | Will return always the same output with the same config if set. |
--output-width | Output image width in pixels where height will be adapted. Smaller width reduces computation time. "-1" will not change the size. |
--output-format {PNG,SVG} | Output image format - PNG or SVG (default: PNG) |
--stroke-width | SVG stroke width (default: 0.1) |
The line-drawer is based on greedy algorithms where for a defined number of lines the best line positions are searched, to mimic the original images as good as possible. The algorithm works as follows:
For num-lines times
Search the darkest pixel in image
Select randomly one of the darkest pixels
For num-lines-to-check times
Get random line through previously selected pixel
Select best fitting and save it to list
For every selected line
Draw line in output image
- python 3
- see requirements.txt
pip3 install virtualenv
virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt
python src/line_drawer.py --input-path ./example/mani_matter.png --output-path ./out_image.png --num-lines 10000
bash test.sh
- Basic idea (https://www.reddit.com/r/Art/comments/454joy/drawing_experiment_every_line_goes_through_the/)
- JavaScript implementation (http://linify.me/about)
- C++ implementation (https://github.com/nathanbain314/lineDrawer)
- Image from Mani Matter (Source: LP Album Cover — Mani Matter — I Han Es Zündhölzli Azündt — zytglogge Verlag)