NEW 3-Week Python for Beginners Course Starts July 27! View Course

Displaying Images in Tableau (with some help from Python)

By Roberto Reif • July 24, 2017

This post was written by Roberto Reif, Metis Sr. Data Scientist based in Seattle. It was originally posted on his blog here

_____

With Tableau, one of the cool things you can do is define every pixel from an image. This allows you to create interesting visualizations as described below. But before we get started, let’s first understand some fundamental concepts about digital images.

DIGITAL IMAGES  

A digital image is a matrix made out of pixels (the smallest element on a screen). In the figure below, we present an image of fruits and vegetables. It can be observed that when we zoom into a portion of the image, it is no longer smooth, but made out of individual squares. Each square is known as a pixel. The size of the image is defined by the number of pixels it has in width and height. The original image below is made out of 1577 x 852 pixels in the width and height, respectively. Therefore, it has a total of 1,343,604 pixels. The more pixels an image has, the better its resolution. The drawback is that the file size is also larger. 

Each pixel has 3 values used to represent the color. The 3 values represent the amount of Red, Green and Blue, also known as RGB. There are 255 possible values that can be used to represent each of the RGB values. The image below shows the amount of red, green and blue used for the original image, and we also show a grayscale version of the image. A grayscale image can be obtained by making the values of the RGB the same.

WORKING WITH TABLEAU

Tableau allows us to define a data point based on its row and column location.  When we view a digital image, each pixel is located at a specific row and column. In the example below, we present an image made out of 4 columns and 3 rows (12 pixels in total). We also made each pixel grayscale with a different value between 0 (black) and 255 (white).

CONVERTING AN IMAGE INTO ROWS AND COLUMNS

To get an image into Tableau we need to create a file format that describes three parameters the row, column and grayscale value of each pixel.  To do this we can use software tools like Python.  Below is a simple script that loads an image, converts it into grayscale, resizes the image, and saves the row, column, and grayscale value into a csv file.  We do not have to resize the image, but in some cases, we can apply this to reduce the total number of pixels in the image.  In this example, we change the image size from 1577 x 852 to 600 x 324.  Note that we roughly maintain the ratio of width/height so the image does not deform. 

The output csv has the following form:

VISUALIZING WITH TABLEAU

We can now bring the csv file into Tableau and we can:

  • - Move the “Row” measure to Rows
  • - Move the “Column” measure to Columns
  • - Move the “Value” measure to Color
  • - Uncheck the “Aggregate Measures”

Note that the row values are in reverse order; therefore, in the y-axis we need to “Edit Axis” and check “Reversed”. 

We can then format the image as shown below. We can observe from the tooltip of the figure below, that we can have information about specific pixels.

Finally, with some clever manipulation, we can expand the above concept and create images based on text as shown below. Here is another great example from Karen Hinson, and a great blog post from Ken Flerlage, who describes a method of extracting an image into a Tableau friendly format without writing code.


I hope you find this helpful! 


Similar Posts

data science
Now Through June 15th, Enroll in Bootcamp Prep Courses at Reduced Price

By Metis • April 17, 2020

Now through June 15th, when you enroll in any of our upcoming Bootcamp Prep Courses (no matter the start date), you'll pay a reduced price of $499. During this difficult time, we hope this reduced tuition opens up more opportunities for those interested in building data science skills in a live online format.

data science
3 Ways to Learn Live Online with Metis

By Jane Durand • March 27, 2020

At a challenging time like now, when remote learning is the only option, our live online capabilities have enabled us to continue serving our students and clients without skipping a beat. Here are 3 ways you can learn live online with us.

data science
Metis Included on Course Report's 35 Best Online Bootcamps of 2020 List

By Metis • June 11, 2020

We're proud to be on Course Report's list of the Best 35 Online Bootcamps of 2020. Here, learn how their team relied on bootcamp-industry expertise and a strict list of criteria to build it out.