Python photo mosaic – for starters

Update – November 24th, 2015

My Github repository for this project: Photomosaic on Github. While trying to get the color enhanced a bit, I’ve tried several different mosaic programs, so don’t get confused. The working program for windows is


Good news on my mosaic program, I got the run-time down from 55 minutes to 3 seconds with some tweaking. The 3 seconds is for a picture 375 x 210 pixels. I also tried a full size 3264 x 2448 pixel photo, it took about 3 and a half minutes to finish. Today I implemented an idea on the project, it seems to bring a bit more color into the mosaic and looks a little more real.

375 x 210 pixel photo:


A larger photo: Long’s Peak

Long’s Peak Original:

Original Post:

How is everyone doing on this Thursday evening? I trust all are doing well and having a good summer.

I am very happy that I got my mosaic project to work today. I was able to output a mosaic from a given photo. The color matching is not yet accurate; however, it does fill in the picture with pictures from the picture database. Yes! – although it is a very preliminary version of the program and took about 55 minutes to run. Yikes! Below is the original picture, my version of the photo mosaic, and the way the mosaic should look.


My Version:

The way it should look:

I got the idea to do this project from someone who had posted a programming help wanted ad on one of the freelance programming sites. Apparently he wanted someone else to do his homework. Anyway, I got the details and decided to give it a try. Here is the original problem.


6 thoughts on “Python photo mosaic – for starters

  1. Thanks for the compliment. Yes, feel free to use the code/algorithm on your own. I have also been thinking about trying to port this solution to Java. I think it would work in JES with Java Advanced Imaging.

  2. I have never used python before so I can’t really read what the code is doing. Because of that I have a little question. How do you compare the pixel (part of the original) to the little picture in you DB? Do you use brute force just compare it with all pictures or do you have some other more sophisticated method?

    1. Yes, it is just brute force. All the DB items are read and the dominate red, green, or blue is value is compared to the small section of the original picture’s red, green or blue value. The closest match is chosen. Its been a while since I worked on this, I know it could be refined somewhat to get a more accurate match.

  3. Hi, i’m new in Python programming and I need help producing a mosaic picture without the artistic touch, just forming a pdf file composed by a array of jpg files, could you help me extracting the code I need ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.