Legolytics Part 1: Extracting Colours From an Image With Alteryx and R
Legolytics Part 2: Assigning the Lego Colour Palette
Legolytics Part 3: All Possible Bricks
Legolytics Part 4: Optimizing Cost
Legolytics Part 5: The Product (you are here)
Get the App
It’s all good developing a solution, but there’s no joy until it’s open sourced. So here is the finished application in all its glory, available to the community via the Alteryx Public Gallery.
Prerequisites
- The application cannot be run in the Public Gallery, or in your own server environments. This is because at present, it is not possible to load images and file inputs in the Alteryx Server product. Therefore, you will need Alteryx Designer, should you wish to make use of the app. Hey, if you don’t, but want your image developed, then just ping me, and I’ll process it for you 😄
- The application requires the predictive tool add-on to be installed (this is free). If you don’t have this installed already, the downloader can be found at licenses.alteryx.com.
- The following R packages need to be installed to the Alteryx R instance:
png
, jpeg
and EBImage
.
This blog will help you install the packages and the code required to run is as follows:
install.packages("png")
install.packages("jpeg")
install.packages("BiocManager")
BiocManager::install("EBImage")
Selecting a Good Image
Once you have confirmed you have all the prerequisites set up, the next step is to get the image you wish to convert into a Lego set.
When creating the image you wish to convert you should:
- Use a square photo
- Have a blank background
- Try and avoid shadow
To help illustrate these rules, here are some examples of what would and would not pass the test. Personally, I always tend to do something like the 4th image, cropping the part of the image that I want to create with the greyscale colours, and setting a background with a square object. (I have terrible paint skills, so it should be a relatively trivial task if I can manage it!)
Running the Application
Well, this bit’s relatively straight forward.
Open the application, select your image, your market (currently GB and US only), and your desired background colour. You should then select the output location and name for the PDF output to be generated.
Once the application has finished running you will likely be presented with one of two things One of those things is the application presenting you with the PDF to view, in which case, great! The second thing is the following error message:
The R.exe exit code (4294967295) indicated an error.
This is what can be referred to as a load of nonsense, and the error can be ignored, your PDF file will still have been generated.
The Result
The result of the application is a PDF file, which contains an image showcasing what your Lego portrait will look like (with brick borders so it can act as instruction sheet should you wish to purchase).
The PDF also contains a table indicating the parts needed to create the set, and web-links to the parts in the Lego online shop.
Onto the Next One…
Well, that’s it. I’ve had a tonne of positive feedback on this over the last year, and have even got a couple of conference talks out of this project, but I’m now putting this to bed (barring a Python release, so look out for that), and looking for my next, slightly weird, data project.
Big thanks to Phil Mannering for volunteering his face for this blog.
Ben