我怎样才能找到带有Mathematica的Waldo? [英] How do I find Waldo with Mathematica?

查看:163
本文介绍了我怎样才能找到带有Mathematica的Waldo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

周末这让我很烦恼:解决这些问题的好方法是什么?href=\"http://en.wikipedia.org/wiki/Where%27s_Wally%3F\" rel=\"noreferrer\"> Waldo? ['Wally'在北美之外]使用Mathematica(图像处理和其他功能)进行拼图?

This was bugging me over the weekend: What is a good way to solve those Where's Waldo? ['Wally' outside of North America] puzzles, using Mathematica (image-processing and other functionality)?

这是我到目前为止的功能,通过调暗
的一些非红色来减少视觉复杂度:

Here is what I have so far, a function which reduces the visual complexity a little bit by dimming some of the non-red colors:

whereIsWaldo[url_] := Module[{waldo, waldo2, waldoMask},
    waldo = Import[url];
    waldo2 = Image[ImageData[
        waldo] /. {{r_, g_, b_} /;
          Not[r > .7 && g < .3 && b < .3] :> {0, 0,
          0}, {r_, g_, b_} /; (r > .7 && g < .3 && b < .3) :> {1, 1,
          1}}];
    waldoMask = Closing[waldo2, 4];
    ImageCompose[waldo, {waldoMask, .5}]
]

这个有效的网址示例:

whereIsWaldo["http://www.findwaldo.com/fankit/graphics/IntlManOfLiterature/Scenes/DepartmentStore.jpg"]

(Waldo是收银机):

(Waldo is by the cash register):

推荐答案

我找到了Waldo!

我是如何做到的

首先,我过滤掉所有不是红色的颜色

First, I'm filtering out all colours that aren't red

waldo = Import["http://www.findwaldo.com/fankit/graphics/IntlManOfLiterature/Scenes/DepartmentStore.jpg"];
red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[waldo];

接下来,我正在计算这个图像与简单的黑白图案的相关性,以找到衬衫中的红色和白色过渡。

Next, I'm calculating the correlation of this image with a simple black and white pattern to find the red and white transitions in the shirt.

corr = ImageCorrelate[red, 
   Image@Join[ConstantArray[1, {2, 4}], ConstantArray[0, {2, 4}]], 
   NormalizedSquaredEuclideanDistance];

我使用 Binarize 来挑选像素在图像中具有足够高的相关性并在它们周围绘制白色圆圈以使用扩张来强调它们

I use Binarize to pick out the pixels in the image with a sufficiently high correlation and draw white circle around them to emphasize them using Dilation

pos = Dilation[ColorNegate[Binarize[corr, .12]], DiskMatrix[30]];

我不得不在水平上玩一点。如果水平太高,则挑选出太多误报。

I had to play around a little with the level. If the level is too high, too many false positives are picked out.

最后我将此结果与原始图像合并以获得上面的结果

Finally I'm combining this result with the original image to get the result above

found = ImageMultiply[waldo, ImageAdd[ColorConvert[pos, "GrayLevel"], .5]]

这篇关于我怎样才能找到带有Mathematica的Waldo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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