Pages

Friday, August 6, 2010

Fridge babe magnets



A common form of analog spam over where I live is the lowly fridge magnet. Many business owners leave promotional magnets on our doors, in hopes that we'll bring them into our homes to serve as a constant reminder to some restaurant's phone number or of a handyman's skills.

I always wondered whether I can cut those magnets into little tiles and rearrange them into a mosaic. As most magnets belong to plumbers (there's a 5:1 ratio between plumber magnets and food delivery magnets, not that I’m insinuating anything about the quality of the food), Ii've decided to celebrate the 25th birthday of the world's most famous plumber. After spending many evenings and weekends, I'm quite proud of the end result. For explanations on how I did it (the Why is obvious – to impress the babes), and why it turned up a little bit distorted, read on.

Click on the image to see it in full-size


How it was done

So, how do you get from this



to a mosaic that somewhat resembles Mario? With a couple of computer vision algorithms, some matching algorithms, and a lot of hard work. No way I'm doing it again without getting paid.


Step 1: Scan your magnets



I've scanned roughly 60 magnets, placing them against a pink sheet of paper, to serve as a contrasting background.


Step 2: Automatically crop each magnet



I had fun playing with a variation on Hough transform in order to automatically extract individual magnets from each scan and rotate them to the right angle (and by 'fun' I mean 'laboriously tried to tune the parameters to get the damn thing to work'). My code was based on this paper, though I haven't followed the method described there through. Which might explain the less than satisfactory results:

Notice that the pink background is showing through.


Here, early in the process errors started to creep in. Not only my auto cropping & alignment algorithm wasn't very accurate, some of the magnets themselves weren't exactly rectangular (i.e. not all of their angles were 90 degrees). Nevertheless, the errors in the following steps were even more critical.


Step 3: Digitally cut the magnets into tiles and make a mosaic



After choosing my target image, I used the Hungarian algorithm in order to find the arrangement of tiles best matching it. Unlike the previous image processing algorithm, I haven't implemented the Hungarian algorithm myself but rather took it from the internet. Quick tip to Python programmers out there - use the code linked from the Wikipedia page. I've tried using another one found on Google that looked prettier, but it was so unoptimized that even after a couple of obvious improvements was taking too long to compile the result (a couple of days).


looks pretty good doesn't it? Well, remember the errors I've mentioned earlier? Now they begin to haunt us.

Step 4: Cut the real magnets into tiles and make the mosaic



Thanks to my brother I got a nifty little tool that should have enabled me to cut the magnets according to the plan laid out by my algorithms.


but -
  • I wasn't able to cut tiles of the precise dimensions. I was off by no more than one millimeter, but as I went further inside the magnet, this error has accumulated.
  • Even worse was the fact that as time progressed the calibration of this guillotine changed a bit, so not all of the tiles were of the same size.
  • And lest us forget the errors I had in scanning the magnets in the first place.
My lesson here is to use lasers the next time I attempt such a feat. Toy guillotines are better than exacto knifes (at least when it comes to keeping all your fingers intact), but not good enough for this task.




Now that I’ve completed setting all the tiles in place, all that was left to do was to hang the mosaic on the wall.

Step 5: Drop the mosaic on the floor


Feel free to skip that step.


I'm not exactly sure what happened, but one moment I had the board on which I constructed the mosaic in my hands, and in the next moment it was on the floor. First I laughed, then I cried. Then I cried some more. When the crying was over, I did the only logical thing to do in such a situation: picked up all the tiles from the floor and started over. I had to reassemble the mosaic from some blurry pictures I had, since I couldn't follow the directions calculated by my algorithms, because they assume that I have the uncut magnets at hand.

Step 6: Hang it on your wall, write a blog post about it




Anyone wants some spare tiles?

Special thanks goes to:



My brother Alon for buying me the guillotine, helping me collect the tiles from the floor after I dropped the board, and proof reading this text.

Nitzan and Ella for giving me some rare blue magnets.

9 comments:

  1. Cool!!!
    I liked step 5... Maybe writing numbers on the back of the tiles would have helped.

    ReplyDelete
  2. Awesome :)
    And funny as always.

    ReplyDelete
  3. Can you describe the "toy guillotine" you used in more detail? I think I could use something similar on a project of mine...

    ReplyDelete
  4. yeah, it was a cutterpede, probably this model:
    http://www.google.com/products/catalog?q=cutterpede&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&cid=4161544703684989124&sa=X&ei=GkmzTcqxMMOZOtPg2J8J&ved=0CB8Q8gIwAA#

    however, I wasn't very satisfied with it. It was very hard for me to cut pieces of the same dimensions, probably because it was made for paper, not for magnets.

    ReplyDelete
  5. Cute & funny idea.

    In our neck of the woods, all the magnets are from law firms... lawyers lawyers lawyers... & a pizza parlor or two.

    (Also liked your Chimp-is-Darwin photo generator. A picture is worth a thousand words.)

    ReplyDelete
  6. Can you share your code? I would like to see it and maybe make some mosaics myself

    ReplyDelete
  7. Hi Eduardo,
    It's really an ensemble of code-bits, one for scanning the magnets, another for composing the mosaic. What are you trying to do?

    ReplyDelete
  8. I want to make some mosaics to place around my house beacuse I really like how it looks. I don't mind if the code is messy, maybe we can make it better.

    ReplyDelete