A simple program that converts an image to a Lego-fied picture.
Here's how this simple package started. (Feel free to skip if you're in a hurry, but why would anyone trying to enjoy Lego and to kill time in a such hurry?)
Originally, I purchased Lego Art Project 21226 (now retired) as the Thanksgiving gift for myself back in 2022, but I didn't have the chance to put up the pieces, since recession is kind of suffocating many folks, including myself.
It is until mid-2023 that I finally had some room to breathe, and I realize that I haven't opened this toy that has been sitting in the corner of my room for like 8 months or so. So I reckon it's probably a decent timing to bring some innocent joy back to my life.
The main bummer is that Lego includes barely enough blocks only to build the images in their manuals (blue blocks are the most common (660 pieces), but considering a 48x48=2304 canvas, it means you need colorful background otherwise you'll run out of some color blocks), and that is not enough if you want to do something fancy. I understand that Lego is a for-profit company, and real hardcore Lego players spend tons of money on buying customized blocks themselves (and I'm not prodigal enough to be one of them). Still, I feel like Lego is not generous enough for such a brilliant idea for this Art Project product.
Another issue is that there isn't a tool that automatically converts a random image into a prototype as if you were to build it in Lego, which means you might spend tons of time working on something that may not be undesirable at the end of the day, and we adults are short on time. This is the reason why I build this package. You're welcome, Lego Engineering team.
Don't get me wrong: I'm still a huge fan of Lego, and I hope this package can save Lego players and likely programmers some time prototyping their ideas.
Please install the package using
pip install lego-image-converter
You can check out some examples on this Colab notebook.
Disclaimer: I do not own any right to the pictures in examples, and they are not intended for profit either. If you're the owner of the pictures and would like me to remove them, feel free to reach out, and I'm happy to remove them for you.
I screenshot the pictures from the Internet, namely
-
The trimming procedure of this package is super dumb because it's too tedious to do the CV stuff (like figure out the center of the picture, majorly and minorly adjust the anchoring point, etc.) for such a mini package and I'm not a CV expert. My suggestion for you is to start your screenshot from the lower left corner, drag it until either the length or width dimension is desirable, and leave extra buffer in the other dimension. The trimming algorithm can only handle this situation properly, so it is not intelligent.
-
I was using a naive Euclidean distance on RGB channel for matching pixels and Lego colors, and it sucks. I found this colormath package useful in addressing the nonlinearities of human vision perception, and it performs decently well.
-
I'm using
unlimited_blocks=True
for the sake of illustration.