Composite image mosaics
We were sent the following through our Ask Us Anything page:
I really like you’re current series of image manipulation in R! Do you know how one might construct a collage image in R? A collage image (perhaps not the correct term?) is an image constructed of many small photos/images combined in a matrix with the overall color of each small image governed by some “master” image. When one looks at the image matrix from a distance it looks like the “master” image but up close you can still see all the smaller images. This seems very possible in R :)
We are very reader-friendly here at is.R(), so of course we hacked together a solution. Now, I don’t know exactly what algorithm the professionals use for this type of thing, so don’t expect professional results from the code in this Gist, but it will allow you to:
- Choose a set of images to serve as the mosaic tiles
- Choose a “master” image to re-build from small versions of the tile images
- Identify the most-similar tile images to each pixel (by proximity in RGB-space)
- Plot each tile image at the appropriate coordinates

