Skip to content

line-drawer recreates a given image by only drawing it by simple straight lines. Implementation inspired by linify.me and written in Python 3.

License

Notifications You must be signed in to change notification settings

ced-mos/line-drawer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

line-drawer

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

Options

--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)

Algorithm

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

Dependencies

  • python 3
  • see requirements.txt

Installation & Execution

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   

Unit tests

bash test.sh

Credits

About

line-drawer recreates a given image by only drawing it by simple straight lines. Implementation inspired by linify.me and written in Python 3.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published