I'm trying to get a Mathematica example working. It's the one on Theo Gray's blog.
I think that Mathematica must have changed since he wrote that code (May 2008), since I'm unable to get anything reasonable out of it, despite changing nearly everything. Do I use ImageData instead of Import? Can anyone suggest a version of this code that works for Mathematica 8?
imagePool =
Map[With[{i = Import[#]}, {i, Mean[Flatten[N[i[[1, 1]]], 1]]}] &,
FileNames["Pool/*.jpg"]];
closeMatch[c_] :=
RandomChoice[Take[SortBy[imagePool, Norm[c - #[[2]]] &], 20]][[1]];
Grid[Reverse[
Map[closeMatch, Import["MendeleevIcon.tif"][[1, 1]], {2}]],
Spacings -> {0, 0}]
The following works (Thanks to @yoda for pointing out the
Reverse[]
thing in the comments):Maybe slightly more streamlined:
Edit
The reason that the original code stopped working in version 8 is that up until version 6 of Mathematica,
Import["file.jpg"]
would return aGraphics[Raster[]]
object. To extract the image data itself you could simply doImport["file.jpg"][[1,1]]
. However, in version 8 (and I suspect version 7) raster images are imported as anImage
by default which means that you needImageData
to extract the image data from the imported files. You can still import raster images as aGraphics[Raster[]]
by usingImport["file.jpg","Graphics"]
so the original code should still work if you adapt theImport
statements, but the advantage of usingImage
objects is that you can use functions such asImageAssemble
(plus a whole range of other image processing tools that comes with Mathematica 8).