A Java pipeline that turns any photo into a buildable LEGO-plate mosaic — downscaling the image, matching real LEGO colors, packing plates with six different algorithms, and rendering a LEGO-look result
Original

Greedy Pack Output

The Lego Picture Generator converts a PNG photo into a real, buildable LEGO mosaic. The pipeline downscales the image into a stud grid, matches each stud to the nearest real LEGO color from a Rebrickable SQLite database, then packs the grid into physical plates using six different packing algorithms — from a fast greedy heuristic to exact-cover search and simulated annealing. The output is a shopping list (bill of materials), an algorithm comparison report, and LEGO-look renders showing exactly how to build it.
Running all six packers on the same stud grid produces a comparison report of piece counts, runtimes, and deltas versus the greedy baseline. Exact methods find provably optimal packings for small same-color regions, while greedy and annealing scale to full images — a practical demonstration of the tradeoff between solution quality and computation time.
This project combined image processing, database-backed constraint filtering, and combinatorial optimization in one pipeline. Implementing the same problem six different ways — and reading the research behind each approach — gave me a much deeper understanding of exact-cover formulations, branching heuristics, and metaheuristic search than any single implementation would have.
Packing Algorithms
Every Stud Covered (Set Partition)
Buildable — Only Real Part + Color Combos