Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

image-processing - 我怎样才能找到带有Mathematica的Waldo?(How do I find Waldo with Mathematica?)

This was bugging me over the weekend: What is a good way to solve those Where's Waldo?

(周末这让我很烦恼:什么是解决那些Waldo的好方法)

[ 'Wally' outside of North America] puzzles, using Mathematica (image-processing and other functionality)?

([ 'Wally'在北美之外]使用Mathematica(图像处理和其他功能)进行拼图?)

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

And an example of a URL where this 'works':

(以及这个“有效”的网址示例:)

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

(Waldo is by the cash register):

((Waldo是收银台):)

Mathematica图形

  ask by Arnoud Buzing translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've found Waldo!

(我找到了沃尔多!)

沃尔多被发现了

How I've done it

(我是怎么做到的)

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

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

(我使用Binarize来选择具有足够高相关性的图像中的像素,并在它们周围绘制白色圆圈以使用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]]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...