Generate Awesome Photomosaics On Linux With Metapixel

Ok, I admit. I thrashed the Digg.com servers for a little while using an open source website mirroring tool, which I wont mention, but it’s easy to find. :)

About 30,000 user icons later, I present to you a product created by a couple very short and sweet command line tools.

1024x768.png

1024×768
1280×1024
1680×1050
1900×1200

On an unrelated note, I’ll be disabling hotlinking of images shortly, so if you’re going to steal my content, please rehost these images yourself.

So how can you make your own mosaic? Simple! Download and install metapixel, if you’re running Ubuntu, it’s located in the universe repository.

Then we are just a few commands away from generating sweet photomosaics. First, we prepare the images.

metapixel-prepare -r source destination --width=48 --height=48

This copies all images from the “source” folder, (recursively) searching into every folder within, and dumps every image it finds into the “destination” folder after resizing them into 48×48 pixel images. You’ll want to modify the width and height to fit the source images. This took a LONG time for me, since my library of images was so gigantic – but once we’re done preparing the images, you don’t have to do it again. Woohoo!

Next, we actually generate the output file(s) with this one liner:

metapixel --metapixel input.jpg output.png --library destination --scale=35 --distance=500

This takes input.jpg and increases the output size by 35 times (i.e. REALLY BIG IMAGE), uses the library destination and does not repeat any images found in the library closer than 500. It’ll spit output.png after a little while. If you don’t care about repeating images, removing the distance flag will result in MUCH, MUCH faster generation times.

Here’s a another I generated, this HUGE image was scaled down from about 228 megapixels.


starrythumbnail.png

In related news, here’s a groovy post over at Kristen Symonds’s blog with a ton of GIMP/Photoshop brushes, check it out, good stuff. :)

Which images would you like to see rendered in Digg user icons? I’ve got lots more ideas but not much time to use them, since I’ve got some holiday shopping to do. :)

I’m back, here are some more…

Bill:
billy.png

Imogen:
imogenthumbnail.jpg

StumbleUpon:
stumblethumbnail1.png

Reddit:
redditthumbnail.png

Ok last update, promise… this is actually pretty darn fun.

Last Jedi Supper:
The original was a 460 megapixels PNG file (30720×15040 – 370MB) scaled down to 7680×3760 – only 28MP, saved as 70% quality JPEG ended up as about a 7MB file… still HUGE! The GIMP was using about 1.2GB of RAM (Thank god I upgraded last week to 4GB!) while scaling the image.

lastjedisupperthumbnail.png

  • http://www.hackosis.com Shane

    Awesome work Wayne. I will add this to my collection of Linux goodies. :)

  • http://www.kristarella.com kristarella

    Very cool rendition of starry night. What were the source images? Kind of look like avatars.

    Thanks for the link. Just curious – how did you find my full name? I know it’s possible, just didn’t know it was easy :)

  • http://www.fsckin.com/ Wayne

    Just a whois lookup on your domain. :)

    The source images are from digg user icons.

  • brian

    just wondering what the mirroring tool is?

    great article as usual!

  • http://www.fsckin.com/ Wayne

    httrack

  • http://distrogue.blogspot.com DistRogue

    If that many people read your blog, Digg is going to get payback for all the sites it inadvertently DDoSed…

  • http://www.fsckin.com/ Wayne

    True enough! Don’t use HTTrack for evil…

    I can remember a few incidents where I left it running and came back to see that I had downloaded dozens of GB worth of data from an extremely unhappy web server.

    I’ve learned to set limitations where it wont download more than say, 500MB at most in a session.

  • http://www.fsckin.com/ Wayne

    Ahhh… hotlinking is now disabled… and I COULD have been evil about it, but nah. :)

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://fsckin.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.fsckin.com/.*$ [NC]
    RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.fsckin.com/hotlinked.gif [R,NC]

    What a superb bit of code! Sorry Roy ;)

    Snap! Hotlinking is a little bit more involved than I thought… I think I’m going to need to use a blacklist instead of a whitelist… time to setup a cronjob and email myself the worst offenders on a daily basis. :) To the person that I broke Google Reader on – whoops!

  • PredatoryFern

    Yeah HTTrack is great but can totally be used for evil, bandwidth consuming purposes.

  • kazamx

    Is there any chance you could give an example for the code to be put into the terminal?

    Say for example I have all the pics I want to use in a folder in my home directory called pics

    I then have the input image in a folder in my home directory called source pic (the actual photo is called pic1.png)

    What would I need to type into terminal, sorry for being so noob

  • David Capito

    Great! Is there a list of user-names of the avatars you used for this project?

    I’d love to check for mine! (Without hours of finding waldo…)

  • rusty

    @kazamx:
    The instructions given earlier suggest using in input image of type jpg, but png should work, as gif does.

    Step 1, create a library folder to toss the icons into:
    mkdir ~/metapixel

    Step 2, convert that library of images you have already, into icons of 48×48 size:
    metapixel-prepare -r ~/pics ~/metapixel –width=48 –height=48

    Step 3, we actually generate the output file:

    metapixel –metapixel ~/source/pic1.png output.png –library ~/metapixel –scale=35 –distance=500

    You did not specify the destination directory for output.png, so it will put it into whatever folder you are in when you enter the commands.

    If the collection of photos you start out with is not large enough, you may need to change the distance value to a smaller number.

  • kazamx

    @rusty,

    Thanks a lot. Your code worked and not my comp is locked up creating my first file :-)

    thanks again
    kaza

  • Pingback: holotone.net

  • Pingback: Make Huge, High-Quality Photo Mosaics in Linux [Digital Photos] · TechBlogger

  • Pingback: Bulk Resizing images using bash « Free….as in free thought

  • onesojourner

    I am an a linux fan but I still prefer andrea mosaic for windows. It has a built in gui and its easy to use and free.

  • http://goinglateral.blogspot.com Yuki

    Hi5 for getting Lifehacker’d, Wayne

  • http://www.fsckin.com/ Wayne

    Yuki: This isn’t the first time. :)

    Lifehacker linked to my interview with David Liu of gOS fame. :)

  • http://www.danielhardy.com Daniel Hardy

    I am very curious about the collection side of this. Where you able to collect only the images or did you have to some how filter them out after the fact. Perhaps another tutorial about running webHTTrack. I am also curious about what hardware you are using and the time to complete this task on said hardware.

    Another great article, keep up the good work.

  • http://www.danielhardy.com Daniel Hardy

    I forgot to mention that you should submit your picture of Imogen to imogenbailey.com… I didn’t know who she was so I went and checked out her site. It looks like they accept user submissions of pictures.

  • http://www.fsckin.com/ Wayne

    Do you know the idea of 6-degrees of separation?

    I spider’d 2 degrees of 1 user with HTTrack, which generated over 30,000 user icons, I can only imagine how many 6 degrees would have given me… probably 500,000 or so.

    I only downloaded the low quality version of the user avatar to save their bandwidth – it has the same filename for each user, so it was easy to filter out everything but png files with a specific name.

    There was very, very little after the fact filtering, since I used appropriate rules to limit the download to ONLY what I wanted to get.

    I did NOT want to really abuse and hammer the crap out of someone else’s servers (that’s just rude), and when I was done I clicked on a bunch of their silly ads to restore my karma.

    I used an open source tool FSLint to remove exact binary duplicates, and right there a TON of people who still use the default avatar are culled, along with people who uploaded the same original file as an avatar.

    In some of these renderings, I changed how often the images could repeat, so for example in the Jedi Last Supper you can see images repeating fairly often when you zoom all the way in.

  • http://seraphyn.deveth.org Seraphyn

    Nice, i don’t knew that i got this one in my Debian Etch repo. Thanks for the hint.

  • daniel

    Wayne, could you post somewhere the images that you downloaded from Digg. I dont want to start downloading them all.

  • http://www.psychic9.com psychic readings

    MetaPixel is AMAZING. I love it

  • Pingback: links for 2007-12-12 « toonz

  • Kanwar

    Hi,
    Truly awesome. Just one question: Where can I get a collection of images to thumbnail for the mosaic? Currently, I have a collection of around 1500 personal images but the generated mosaic is still non-descript. I cannot specify a distance of more than 25.

    Is your image collection somewhere on the web — i.e. freely downloadable?

    Thanks.

  • http://techmalaya.com Syahid Ali

    awesome post man. must try.

  • Pingback: Sp3w

  • http://sendderek.wordpress.com SendDerek

    Thanks for putting this how-to together, Wayne. I learned a few extra commands from it that I didn’t know of before.

    If any of your readers are interested, I’ve had a tutorial made for a while now that outlines this same process. The only difference is that I’ve used a few other tricks and commands to get the results that I was personally after. It may help your readers too.

    Here’s the link:
    Great Photo Mosaics with Metapixel

  • fistikuffs

    Hey can some one help a total noob with this? `When i type the command to prepare the pics i get this:

    Usage: /usr/bin/metapixel-prepare [OPTION]…

    Prepares all images in for use as small images in
    photomosaics. The scaled versions and the table file are
    stored in .

    –help display this help and exit
    –width=WIDTH specify width of small images
    –height=HEIGHT specify height of small images
    -r, –recurse recurse through directories
    –debug print out debugging info
    :
    As i’m new to linux i don’t know what i’m doing wrong. I’ve copied the source folder to my home folder and created the destination folder there and followed the instructions posted by rusty but i still get that same output. I know i must be doing something dumb, can anyone help please?

  • Pingback: links for 2007-12-18 « B I T Z

  • Pingback: Top Linux Headlines of 2007 | fsckin w/ linux

  • Chinmay

    Sorry about the hotlink. Removed it…I just read the comment today…Btw…great blog..

  • Pingback: Generate Awesome Photomosaics On Linux With Metapixel | oogleauto.com

  • http://augustus145.wordpress.com Scominano

    Her fare quickly wasn’t in it.

  • HALP

    Uhh..Wow. I need some help with my mosaic. I think I may have done something wrong:

    Image Type: png (The PNG image format)
    Width: 58816 pixels
    Height: 36800 pixels
    Size: 1.5 GB (1557661764 bytes)

    When I try to open it:
    “Insufficient memory to store a 58816 by 36800 image; try exiting some applications to reduce memory usage”

    When I try to open it in firefox – firefox complains it contains errors.

    Now, should I make a smaller one or is there some how I can view this and then print it to make one helluva poster?

  • HALP

    Is it just that it is too big or are there errors?

  • HALP

    Heh..triple posting for the win.

    Anyway. Opening it with gimp – taking a while but it may work.

    Nope – gimp froze.

  • http://www.kristarella.com kristarella

    Halp, it’s a damn big image and some programs will have a heart attack.
    GIMP should be able to open it – eventually. You’ll need a lot of patience… put a movie on or something!

  • HALP

    Is there any other program that can open it besides gimp?

  • http://www.kristarella.com kristarella

    Sorry, no idea.

    Are you really trying to make a poster 16 feet long? Because that’s what you’re file will produce printed at 300dpi. I don’t think large posters are usually printed at high resolution because they’re designed to be viewed far away, they don’t need to be high res.

    I think you might just need a smaller file to open it with a regular computer.

  • HALP

    Abandoning this now is madness! I must follow through! Wayne – I am calling upon you for you guidance! NOW ANSWER ME!

    kthxbai

  • HALP

    Nevermind just scaled it down…was not that good of a mosaic actually.

  • Pingback: VS#34: I’m in my Prime - 803.693.6552 | Valid Syntax

  • Pingback: Linux » Blog Archive » Generate Awesome Photomosaics On Linux With Metapixel

  • http://www.blogger.com/profile/6708993 Gina

    Sweet! I want to pixel the universe!

  • http://links.cse.msu.edu:8000/members/matt_gerber/index.php/Main_Page matt
  • Matt

    I’ve written a GUI for MetaPixel, which can be found here:

    http://links.cse.msu.edu:8000/members/matt_gerber/index.php/Software#MetaPixel_GUI

    The GUI makes it _much_ easier to create mosaics of a specified size.

  • Matt

    oh wow…didn’t notice the duplicate post. delete one, please :)