Digital String Art

I came across an article on creating art with string / yarn across a grid of points on the outer edge. I was curious whether I could generate an algorithm to convert an image to this form.

  • I chose python since I figured it was the most flexible for experimentation

  • I chose the following packages:

    • Pillow (Python Image Library [PIL]) for retrieving pixel information

    • svgwrite for creating SVG files, which seemed to fit for creating line art

    • svglib and reportlab.graphics for converting SVG into PNG

Prototype 1

For the first prototype, I attempted the following:

  • Read the source image and divide into a grid, where color for the grid is averaged and also converted to L*a*b for color comparison.

  • Create a list of endpoints around the image as the start / end points for the strings.

  • Identify the number of desired string passes based on lightness / darkness

  • Allow any number of passes for transparent cells

  • Iterate over each cell and find a line which passes through it while not violating cells with a maximum number of passes allowed.

  • Continue to iterate until all required passes are satisfied or exceeds the maximum number of passes.

Test Case 1

Source Image

Output

Results

The processing took quite a long time and stalled out without achieving the desired passes.

I am thinking that the algorithm is off and perhaps I should iterate over all possible line combinations and find the dominant color across all cells.