A couple of decades ago I saw a news report about a guy who creates pictures from smaller pictures so that a larger picture is visible from afar but when you approach closer it is composed of smaller images. What I was surprised is that that guy was selling them for 6 figures. Remember, that was before the 2000s, and the computing power of computers was not that great.
So, I took a week or two to think about how I could replicate that as I didn’t think that was that hard. It turns out it is not. What I did, at that time in Delphi was code a program that takes in a large image, and a pool of smaller images. Then, segment a larger image into a 2D grid with the size of smaller images.
Each grid segment was then compared with all of the smaller images per pixel. As you might imagine that was extremely computationally expensive but at that time there was very little documentation about it. The process went that I took one grid element, inverted it, took the smaller image, and compared it per pixel. Elements that were not the same showed up in the resulting image while identical pixels were black. Then just go around the resulting image and count how many black or close to black pixels were in the image and create a percentage of it. Images with the biggest similarity percentage were placed as a tile.
It worked … well enough that my curiosity was satisfied.
Fast forward to now.
It always bugged me that I never pursued that idea further, and a month ago I wanted to check what was new in the field of making mosaics. To my surprise, not much. I’m surprised that Image mosaics are not more prevalent as they are really fun illusions. I did find an interesting DeviantArt page that has a lot of mosaics so if you are interested, check it out.
The test will be done using Python and a community-driven Image processing library that’s much faster than doing the raw low-level pixel manipulations of pixels by python itself. So we add the Scikit-image library to the mix. Then created a test script and it works great. I’m able to create huge mosaics, like over a gigabyte and tens of thousands of pixels wide. If I get enough interest the code will be made public, until then here are some of the first methods I tested and later discarded. More promising methods will come in later posts.
Our test image will be the universally acclaimed test image - Lenna. The dataset used is ACeleb which has mosaic as its main image, so.. that’s fun.
Lenna size is 1024x1024 pixels, tile size is 10x10pixels and we have 2819 images to test for each tile.
First Test Algorithm is the distance between colors. It’s the fastest method.
Next is Histogram. Some online sources swore by histograms to compare images but it’s just not the case. They do capture subtle differences but without structure, that difference is all over the place. Also, if the image is noisy, you get garbage out. The noise is not visible to the naked eye but the histogram picks it up. Histogram can be a good choice for large images with little noise but at that scale you can be better off with simple color distance, depending on your tile size of course. If tile size is small, color distance, if tile size is large, histogram. That is if there are no other methods we will look at, so…
Scikit has a histogram function and several different methods for comparing them. The first one we will check out is Correlation.
So, to summarize this. Histograms are not that good, the nearest color is but we lose details.
The search continues… Next time on Barn Lab: mean squared error, peak signal-noise ratio, normalized root mse, Hausdorff distance, structural similarity, adapted rand error, contingency table, adapted rand error, and normalized mutual information. Not all will probably fit into a single post so subscribe to keep informed.