Skip to main content

minor update after formal release

Project description

lego_image_converter

A simple program that converts an image to a Lego-fied picture.


Background

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 have some room to breath, 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 (like 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 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 on 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 is undesirable, 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 as well some time prototyping their ideas.

How to use

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 of 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 it, feel free to reach out, and I'm happy to remove it for you.

I screenshot the pictures from the Internet, namely

  • Tsunami from here.
  • Cheetah's logo from here.
  • Twitter's logo from here.
  • Doge's logo from here.

Notes

  • 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 at all.

  • 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lego_image_converter-0.1.2.tar.gz (8.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page