- Notifications
You must be signed in to change notification settings - Fork3
Simple brick mosaic generator
License
merschformann/brickmos
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
brick-mosaic
This is a simple tool for converting images to Lego mosaics such that theirparts can be ordered quite easily from bricklink (https://www.bricklink.com/).I wrote this for myself for a birthday present I worked on, but wanted to leaveit here for others to re-use or as inspiration.
(ltr: original image, pixelated image with original color, image with colorsmapped to given Lego colors;image source)
This is a rather simple script which worked well for me, as I went back andforth between my image editing tool and modifying the color pallet. I reallylike this continuous process of shaping the result while keeping colors/bricktypes and their prices under control. I even ended up replacing one 1x1 platewith a 1x1 tile, since the respective color was too expensive on bricklink.Furthermore, I was only interested in full 1x1 mosaics, similar to the Legomosaic art product line. I also ended up buying the frame parts used for theLego art frame, as it is extendable and easily wall-mountable (seehere).
However, if you are more interested in a GUI application, different workflow orautomatically chosen larger than 1x1 pixels, you may want to have a look at thefollowing alternatives (if I forgot an alternative here, let me know):
- Bricklink studio (full-blown brick set designer with a mosaic feature, (seehere)
- PicToBrick (specifically made for brick mosaics, seehere)
The following should get you started.
Main dependencies are:
- Python (I used python 3.8)
opencv-python
(the version I used is defined inrequirements.txt)
If you run into problems missinglibGL.so
, install the following:
sudo apt updatesudo apt install libgl1-mesa-glx
Install via PyPi
pip install brickmos --upgrade
Convert an image by invoking the script as follows:
brickmos --image_file data/iron-man-portrait.jpg --output_directory="temp"
Or alternatively clone this repo and run it directly:
python run.py --image_file data/iron-man-portrait.jpg --output_directory="temp"
Repeat the process while modifying the original image (change colors in areasnot working well, change colors overall, etc.) and limiting / extending thecolors (add useful ones, remove expensive ones) until you are satisfied with theoutcome (and price ;) ).
- Login athttps://www.bricklink.com/
- Go toWant > Upload (seehere)
- ChooseUpload BrickLink XML format
- Copy & paste (ctrl-a, ctrl-c, ctrl-v) the XML output of the tool into the window
- Proceed to verify items and add all to a wishlist (please double-check theitems, before ordering)
Find some further definitions below.
Find a short explanation of the parameter arguments below.
--image_file, -i
: the path to the (original) image to process, can be a.jpg or.png file
--color_file
: the csv-file defining the brick-colors to be used (if notgiven, colors.csv at script location is attempted), see format descriptionbelow--output_directory, -o
: the directory the output image and BOM is written to(default is current working directory)--spares
: the number of spares to add per color/brick (in bricklink BOM),just in case of loosing some bricks--size
: the width/height of the image in 1x1 bricks (default is48x48 -same as current Lego art)--grid_cell
: the size of one cell in the helper grid (e.g.:4x4), thehelper grid is useful as a guide when finally placing the bricks, it can bedeactivated by specifyingnone
The set of available colors is defined by the csv-file (--color_file
, seeabove). The following information is required.
rgb ; Bricklink Color Name ; Bricklink Color ID ; Bricklink Part ID255,255,255 ; White ; 1 ; 3024175,181,199 ; LightBluishGray ; 86 ; 302489,93,96 ; DarkBluishGray ; 85 ; 302433,33,33 ; Black ; 11 ; 3024
This is an example set of colors for a 4 'color' black & white picture using 1x1plates. The example is already in expected format. The format requires a headerline and semicolons as column delimiters. The values used here should be alignedwith the definitions on bricklink for the export to work properly (seehttps://www.bricklink.com/catalogColors.asp).
More details about each column:
- The first column is the RGB value of the corresponding color. There is noofficial definition of these from Lego, thus, use something as close aspossible you can find. I picked the colors defined on the bricklink page.
- The second column is just a recognizable name for the color. Using thebricklink name seems reasonable.
- The third column is the bricklink color ID (see page mentioned before). Thisis important for the XML-export to function properly.
- The fourth column is the bricklink brick type ID. You can find these inbricklinks database. Since the script only considers 1x1 parts, only theseshould be used. The3024 from the example is the 1x1 plate (seehere).Other options include, but are not limited to, 1x1 tiles (3070b, seehere)or 1x1 plate round (4073, seehere).Note that prices varya lot with colorAND brick type. For my own mosaicI used 1x1 plates, but replaced an expensive color with a much cheaper 1x1tile.
About
Simple brick mosaic generator