Mathematica中的照片马赛克:Mathematica 8中的2008年示例无效 [英] Photo Mosaic in Mathematica: an example from 2008 doesn't work in Mathematica 8

查看:129
本文介绍了Mathematica中的照片马赛克:Mathematica 8中的2008年示例无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Mathematica示例工作.这是 Theo Gray的博客上的那个.

I'm trying to get a Mathematica example working. It's the one on Theo Gray's blog.

我认为Mathematica自从他编写了该代码(自2008年5月)以来,一定已经进行了更改,因为尽管更改了几乎所有内容,但我仍无法从中获得任何合理的信息.是否使用ImageData代替Import?谁能建议该代码适用于Mathematica 8的版本?

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}]

推荐答案

以下工作原理(感谢@yoda指出注释中的Reverse[]内容)

The following works (Thanks to @yoda for pointing out the Reverse[] thing in the comments):

f = FileNames["*.jpg", {"c:\\test\\pool\\Pool"}];
m = Import["c:\\test\\pool\\Pool\\MendeleevIcon.tif"];
imagePool =
  Map[
   With[{i = Import[#]},
     {i, Mean[Flatten[ImageData@i, 1]]}] &, f];
closeMatch[c_] := 
  RandomChoice[Take[SortBy[imagePool, Norm[c - #[[2]]] &], 20]][[1]];
Grid[Map[closeMatch, ImageData@m, {2}], Spacings -> {0, 0}]

这篇关于Mathematica中的照片马赛克:Mathematica 8中的2008年示例无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆