Loom Art in Tableau


Recently, I completed a project which entailed visualizing the digits of Pi in an artistic manner (see The Beauty of Pi). One of my main goals was to create a circular image with each value (0-9) grouped together, then each digit of Pi connected using a curve (a Bézier curve to be precise). Here’s an example of what I created (Note: this visualization is not included in the original post):




As you can see, I was able to get it working as desired, but this was my first time using Bézier curves and I struggled a bit with it. After fighting with the table calcs for a while, I reached out to Chris DeMartini, who is the expert in Bézier curves in Tableau. Chris, recognizing what I was trying to do, sent me the following visualization on which had done something similar.



When I saw this and realized what it was doing, I was completely amazed as the loom image was made completely of Bézier curves. This was some truly fascinating stuff. But I returned to the task at hand and used the viz to help me correct my table calculations. It was just the push I needed and, as you can see above, I was able to correct my problems.

But, after I had finished the project, I kept thinking about the loom image Chris had created and I started to wonder if it were possible to convert any image to such a pattern and visualize it in Tableau. So, I began doing some research, starting with the links on Chris’s visualization.

A circular loom is a round apparatus used for weaving yarn or thread. It typically has 200 pins which are used for stringing the thread. In 2016, an artist named Petros Vrellis created an algorithm which takes a digital image, analyzes the dark and light spots, then outputs a knitting pattern, allowing him to re-create that image on the loom using a single length of thread. The video below shows the process in action.


Incredible, isn’t it!

The Algorithm
For the Tyrion Lannister image, Chris got his data and rendering algorithm from an html canvas version available here: Tyrion Lannister Image. But, as I said earlier, I wanted to be able to take any image and create loom art. Mr. Vrellis had committed to open-sourcing his code, but I was unable to find it. I did, however, find a number of algorithms on Github that did basically the same thing. I chose one, created in Java by the user, shlonkin, which seemed to give me what I needed. One problem with the code was that it didn’t actually output the details of each line it created—it placed everything into arrays and created an on-screen image, but didn’t actually output the data. After taking the code apart, I was able to add a handful of lines to output a csv file (At the end of this post, I’ll direct you to my modified version of the code, as well as provide instructions on how to use it to create your own loom art). I should note that I am not a Java programmer, but I have a programming background and can make sense out of just about any language you put in front of me. But writing code in that language can often be an entirely different story. So, if you are a Java programmer, it’s likely my code is not up to snuff, but it works!

From here, I started uploading image after image to see how they looked. It’s important to note that the algorithm does not do a great job with every image. For instance, I attempted to generate the loom pattern for a number of artworks from Escher, Picasso, and Salvador Dali, but none of them were even remotely recognizable. It’s difficult to predict which images it will do well with and which it won’t, but my theory is that there needs to be a fairly clear distinction between the foreground and background or else everything will just sort of blur together. That being said, I had a lot of fun uploading various images and seeing the results.

Visualizing in Tableau
Now that I had the data in a CSV file, I was able to put it into Tableau and start to visualize it. This was very easy as it was just a matter of drawing lines using the paths generated by the code (this is included in the how-to section, in case you haven’t done it before). The first image I plotted was Afghan Girl, a famous portrait by Steve McCurry which appeared on the June 1985 cover of National Geographic. Here’s the original:



And here’s an animation of the loom version being “drawn” line-by-line:


In the end, I created a visualization that includes 10 different photos and paintings, most of which I expect you’ll recognize. I also included a version of Chris’s original Tyrion Lannister photo. In addition to allowing you to change the color of the thread, the visualization also allows you to show anywhere from 1 to 4,500 lines. For instance, here’s are a series of images showing 1,000, 2,000, 3,000, and 4,500 lines. Note: You can click on each image to see the interactive version.

1,000 Lines

2,000 Lines

3,000 Lines

4,500 Lines


I should point out that Chris used Bézier curves with a slight bend, rather than straight lines. This has a small, yet noticeable impact on the overall quality of the images. However, I chose to just use straight lines as they are easier to create and I found that a slight increase in the number of threads helped to enhance the overall quality.

How-To
So, I don’t know if anyone will be interested in actually creating some of their own loom art in Tableau, but if you’re interested, here’s are the steps required:
  1. Download and install the Processing IDE: https://processing.org/download/
  2. Download the ImageLoom.pde file from my Github repository: https://github.com/flerlagekr/AutomatedArt
  3. Open the ImageLoom.pde file in Processing.
  4. Follow the instructions in the comment block at the top of the code (don’t worry—they’re simple).
  5. The program will output a csv file. Connect to it with Tableau.
  6. Move X to the Columns shelf and Y to the Rows shelf.
  7. Move Path to the Detail card.
  8. Change the chart type to Line.
  9. Move Path  Order to the Path card, then change it to a Dimension.
  10. Change the size of the lines to the smallest possible.
  11. Change the color to black (or whatever thread color you prefer).
  12. Change the color transparency to a low value (5-15% seems to work well).
  13. Change the y-axis to Reversed.

The screenshot below shows the final result.



And that’s all there is to it. If you happen to create your own loom art, then I’d love to see it!

Update, 11/08/2017: As I noted above, the real workhorse in this process is the algorithm that chooses the paths of the lines to be written. I borrowed the code from the user, "shlonkin" on github (I'm trying to get more details about this person so I can give her/him proper attribution on this post), but others have written similar code. In fact, after posting this blog yesterday, Roberto Reif referred me to a brilliant post he wrote last November. If you are interested in the technical details of how these algorithms work, then I definitely recommend reading Drawing with Straight Lines.

Ken Flerlage, November 7, 2017

22 comments:

  1. Wow. Ken, this is extraordinary. I love the energy in the way this blog is written - your excitemen comes through in the tone of the writing. This was the same experience I had when building my Kraken vizzes a few years ago. Truly well done!

    ReplyDelete
  2. Simply amazing Ken. My morning is off to a good start now that i have seen this post.

    ReplyDelete
  3. Hi Ken, this is fantastic! I attempted to create some loom art of my own, and after hitting the compute button I repeatedly get an error: "Problem writing to the file. Closing file..." Any ideas why this might be happening?

    ReplyDelete
    Replies
    1. Yes, someone actually pointed it out to me earlier today. If you take another look at the code on github, I've updated the instructions to address this issue. There is a line of code (line 171 or 172 depending on when you downloaded it) which sets a path for the output folder. That needs to be modified to match a path that exists on your computer.

      Delete
  4. Thanks Ken, great instructions. It was fun to test out tonight. Once i get a good image, I'll post.

    ReplyDelete
  5. So glad I found this blog.... such beautiful images and creative ideas.

    ReplyDelete
  6. How did you produce the line-by-line animation as a gif? I could imagine how to create it step by step using the pages shelf, but is there an easy way to export each 'frame'?

    ReplyDelete
    Replies
    1. I used a tool called ScreenToGif (http://www.screentogif.com/) that was recommended to me by another Tableau author. It basically allows you to capture a segment of your screen. So, you can use pages to animate on Desktop then let the tool capture a gif.

      Delete
  7. Awesome work Ken, Inspired!!
    One question, How did you get the 'Group' field that you have used in animation?
    Should i create it manually in Excel?

    ReplyDelete
    Replies
    1. I created it manually in Excel. You can find the template here: https://www.amazon.com/clouddrive/share/oVulYdCzJ122zeea47gwwryWFBpVxHNbpYgKWfCQCPK

      Delete
  8. This is great. Tried it today but unfortunately I am getting the error as: "size cannot be used here". any idea!

    ReplyDelete
    Replies
    1. Somehow I never saw this message. Sorry about that.

      Delete
  9. Ken, I admire your work. I have a CSV file with coordinates for a rectangular loom. How can I identify the nail location from the CSV file coordinates. e.g. 60, 80 refers to lower x axis nail 60 and left y axis nail 80 etc., but how can the top x axis and right y axis nail locations be identified. I hope that is clear. I look forward to your feedback.

    ReplyDelete
    Replies
    1. Why do you need to identify the nail location? If you have a CSV generated by this process, then you can just plot it directly in Tableau. Can you clarify what exactly you're trying to do?

      Delete
  10. Simply love your post! You really help people to learn. One thing though is I can't find where the the numbered nails are. Maybe I am not reading it right? Everything else I got, but don't see where to start, what nail number is next and so fourth, just a beautiful picture.I want to physically make a loom art.

    ReplyDelete
    Replies
    1. Can you contact me via email? I think it'll be easier that way. flerlagekr@gmail.com

      Delete
    2. I'm having the same issue -- I can't figure out how the pins are connected, from the CSV. It might help others if you could clarify publicly :) Thank you in advance!

      Delete
  11. is there any way to export some instruction for making physical model without cnc ?
    something like this :
    String #0 -> next pin: 112
    String #1 -> next pin: 134
    String #2 -> next pin: 116
    cvs gives xy of points , the thing we need is pin number, and step by step instruction to make

    ReplyDelete
    Replies
    1. The goal of this was to be able to create these images using the Tableau software package, not necessarily physical artwork. But I've been in contact with some folks who have used this to create a physical work. Happy to put you in touch with them if you can send me an email. flerlagekr@gmail.com

      Delete

Powered by Blogger.