1. Select a source image
Use the file selection tool to choose a file from your hard drive (or take a photo with your camera, if accessed from a phone). The image will be processed entirely in the browser. Nothing will be uploaded! After opening the image, you will see a preview below the file input. You can choose to squeeze the image into the final mosaic size, or crop the middle region and keep the aspect ratio. Furthermore, sliders below the preview image allow for (optional) modifications of brightness, contrast, and color. If your image has a black background (RGB=0,0,0), you can use the "Ignore black regions" option to focus the algorithm on the foreground object.
2. Choose the size of the mosaic
Use the inputs to select the size of the mosaic. A lego art mosaic has a size of 48 x 48 studs. From two sets you can build a 64 x 64 mosaic. You can choose any arbitrary mosaic size. The number of parts required to build the mosaic is displayed below.
3. Select the lego art sets for the mosaic
Available lego art sets are displayed in step 3. Use the input elements to adjust how many of each set you would like to use for the mosaic. The website internally stores how many parts (and of which color) are present in the sets. The number of available parts is displayed according to the user input.
4. Calculate mosaic
Use the "Calculate" button to start the calculation of the mosaic. The button is only active if the number of available parts in step 3 is larger than the number of required parts (step 2). The calculation takes a few seconds to finish. The progress of the computation is indicated.
5. Download instructions
The website can generate a pdf with building instructions for you. When the calculation of the mosaic finished you can access your pdf with the "Download instructions (pdf)" button. In case the "Ignore black regions" option is chosen, ignored regions in the mosiac are labeled with "?" in the instruction. Fill these regions with remaining bricks.
How it works - the algorithm
The first step in creating lego art from custom images, is resizing to the final mosaic size. A bit of random noise is added to the raw color values to break color ties later on. Next, the color of each individual pixel is compared to all available colors within the selected brick sets. A color distance is calculated as the squared distance in RGB space. I have been experimenting with different color spaces, however, found that RGB works just fine. The actual calculation of the mosaic happens in two phases. First, the pixels are filled one-by-one with the best available color. If the best color is not available due to part limits, the next best color is chosen. In the second phase, parts are exchanged to improve the overall color match: pairs of parts are swapped, longer chains of parts are rotated (e.g. A→B, B→C, C→A), and spare parts from the sets are swapped in. This continues until no such exchange can improve the result anymore, which guarantees the best possible mosaic for the available parts (the lowest total color distance).