Hello,
for my first post on these groups (hi all!), here is a small recreational function combining ImageIdentify and image search on the web. The idea is to start from a given word (or sentence, or...), search for the internet for images corresponding to this word, and then perform ImageIdentify on the result, which gives a new word. And to repeat the process until we get with ImageIdentify what we are searching for. It can lead to nice/surprising/funny combination of text and images.
Technically, the function just combines ImageIdentify and image search, and uses FixedPoint to repeat the process until we find the result. The final function is called ImgPlayFixP, which takes a string (the initial word) as argument:
ImgPlay[x_?StringQ] :=
Module[{a, a2, b, xx}, xx = StringReplace[x, " " :> "+"];
Sow[xx, "name"];
a = Import["http://images.google.com/search?q=" <> xx, "Images"];
If[Length[a] > 0, a2 = RandomChoice[a],
a2 = First@
Import["http://images.google.com/search?q=mickey+mouse",
"Images"]]; Sow[a2, "Image"];
b = StringReplace[#, " " :> "+"] &@
CommonName@ImageIdentify[a2, SpecificityGoal -> "High"]; b]
ImgPlayFixP[x_?StringQ] :=
Module[{aa},
aa = #[[2]] &@Reap[FixedPoint[ImgPlay, x, 10], {"Image", "name"}];
Grid[{StringReplace[#, "+" -> " "] & /@ aa[[2, 1]], aa[[1, 1]]},
Frame -> All]]
A bit of randomness is present (random choice of the picture among the results), and in the case where the search gives no result, we use a picture of Mickey Mouse (because why not...).
Here is another version of the function, which does not need any input, and uses a random word instead (RandomWord function):
ImgPlayFixPRandom[] :=
Module[{aa, w}, Off[$CharacterEncoding::utf8];
w = RandomWord[{"KnownWords", "Noun"}]; Print[w];
aa = #[[2]] &@Reap[FixedPoint[ImgPlay, w, 10], {"Image", "name"}];
Grid[{StringReplace[#, "+" -> " "] & /@ aa[[2, 1]], aa[[1, 1]]},
Frame -> All]]
Here are a few example of results (note that because of the randomess, you can get different results when starting with the same word). The last two were obtained with the "random word" version. Reading of the pictures: the initial word is the one on the top left; this word gives the image on the bottom left; Imageidentify on this image then gives the word on the second column, etc. The last image corresponds to a fixed point.
The code can certainly be improved. It could also be fun to run the function on a very large number of initial words, and to plot a graph showing the "trajectories" of the function among the words...
Thibaut