# Visual motion illusions

**URL:** <https://community.wolfram.com/t/visual-motion-illusions/20264>\
**Category:** Staff Picks\
**Tags:** image-processing, optics, computational-arts, geometry, high-performance-computing, staff-pick, computational-humanities, video-processing\
**Created:** [July 11, 2022, 12:06pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264 "2022-07-11T12:06:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikmahieu](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/erikmahieu/32/8091_2.png) [@erikmahieu](https://community.wolfram.com/u/erikmahieu)\
**Post date:** [July 11, 2022, 12:06pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/1 "2022-07-11T12:06:49Z")

</div>

![introVideoC.gif](https://global.discourse-cdn.com/wolfram/original/2X/1/117e18edadaa04e5601754e7e27fd720d8d0d99b.gif)

How come something that does not move is nevertheless perceived as moving? This [post on Twitter by Jacob Yates](https://twitter.com/jcbyts/status/1336666963804909573?lang=en) explains illusions in motion perception and inspired me to look into it using Mathematica. The theory behind this illusion of motion, is explained by Adelson and Bergen in their article:

> [`Spatiotemporal energy models for the perception of motion`](http://persci.mit.edu/pub_pdfs/spatio85.pdf)

A video is a sequence of frames (still images) changing over time and can be represented as an x - y - t space. The frames are then cross sections perpendicular to the t-axis. To detect movement in the video, we make cross sections perpendicular to the x- or y-axis.  
Here is simple video containing a static and a moving vertical line:

```
AnimatedImage[
 Table[Image[
   Graphics[{AbsoluteThickness[25], Red, 
     Translate[Line[{{0, -1}, {0, 1}}], {x, 0}], Blue, 
     Line[{{0, -1}, {0, 1}}]}, PlotRange -> 1.25], 
   ImageSize -> {200, 200}], {x, -1, 1, .1}]]

```

![1717linesdemo.gif](https://global.discourse-cdn.com/wolfram/original/3X/a/e/ae3fe900be0ac33a3845b2e8b0943a92d3bdfcf5.gif)

If we make a cross section perpendicular to the y-axis, we see the static (blue) line mapped as a vertical line and the moving (red) line is mapped as a slanted one.

```
ImageGraphics[
 ImageAssemble[
  Table[{ImageTake[vfLstL[[frm]], {30}]}, {frm, 1, 21, 1}]], 
 AspectRatio -> 1, Frame -> True, 
 FrameLabel -> (Style[#, Bold, 14] & /@ {"-- x --", "frame (t)"}), 
 ImageSize -> 350]

```

 ![6862demolinexyt.png](https://global.discourse-cdn.com/wolfram/original/3X/f/c/fc6fcf01bed44a5d98e94e34f00f66f96e96eabc.png)

According to the above article, motion is perceived when there is orientation in x - y - t space . In our case , motion will only be observed when there is slant in the x - t diagram .  
We converted a video to an x-t diagram but we can equally convert an x-t diagram to its corresponding video. Here is a function that does this:

```
makeVideo[xtDgm_] := 
 Module[{w, h}, {w, h} = ImageDimensions[xtDgm]; 
  FrameListVideo[
   Map[Image[ParallelTable[PixelValue[xtDgm, {x, #}], h, {x, w}]] &, 
    Range[h]], FrameRate -> 30]]

```

Movement in a video means slant in the x-t diagram. A simple case is that of moving vertical lines. Here is the x-t diagram and the video derived from it:

```
xtDgm = Image[
  Graphics[
   Table[{AbsoluteThickness[8], Line[{{0, d}, {1, 1 + d}}]}, {d, -1, 
     1, .1}], PlotRange -> {{0, 1}, {0, 1}}], ImageResolution -> 20, 
  ImageSize -> 100]

```

 ![xtDgm.png](https://global.discourse-cdn.com/wolfram/original/3X/e/5/e56819a17403959729f874a12214ca6a6ddc7950.png)

```
makeVideo[xtDgm]

```

![xtDgm.gif](https://global.discourse-cdn.com/wolfram/original/3X/9/e/9e5bf89ee277ce0f2b9bbd9a56f1860ba444ef2c.gif)

For our demonstration, we want only the left- and rightmost lines to move. For that we need an x-t diagram with lines that are slanted only at both ends:

```
xtDgm2 = 
 Image[Graphics[
   Table[{{AbsoluteThickness[9], 
      Line[{{0, 
         d}, {.2, .2 + d}, {.8, .2 + d}, {1, .4 + d}}]}}, {d, -.5, 
     1, .1}], PlotRange -> {{0, 1}, {0, 1}}], ImageResolution -> 20, 
  ImageSize -> 100]

```

 ![xtDgm2.png](https://global.discourse-cdn.com/wolfram/original/2X/4/4f57a8a136303564a7a4f4632f8e2f14340ac0fe.png)

```
makeVideo[xtDgm2]

```

![xtDgm2.gif](https://global.discourse-cdn.com/wolfram/original/3X/6/1/6190e46ca36a04f436f2b78d63d4221fd484a00e.gif)

To perfect this, we need filled and partially slanted strips to fill our x-t diagram. These two functions achieve this for both right- and left moving lines:

```
edgedStripR[y_, w_, h_, d_, 
  col_] :=(*y is y position of center, w is 1/2 of total width, d is \
fraction of 1/2 w, h is 1/2 of total height, col is the filling color*) \
{col, Polygon[{{-w + d w, y - h}, {-w, y - h - d w}, {-w, 
     y + h - d w}, {-w + d w, y + h}, {w - d w, y + h}, {w, 
     y + h + d w}, {w, y - h + d w}, {w - d w, y - h}}]}
edgedStripL[y_, w_, h_, d_, col_] := {col, 
  Polygon[{{-w + d w, y - h}, {-w, y - h + d w}, {-w, 
     y + h + d w}, {-w + d w, y + h}, {w - d w, y + h}, {w, 
     y + h - d w}, {w, y - h - d w}, {w - d w, y - h}}]}
Graphics[edgedStripR[0, 2, .2, .2, Gray], Axes -> True, 
 PlotRange -> {{-2.2, 2.2}, .5 {-1.5, 1.5}}, ImageSize -> Medium]

```

![10757edgedstrip.png](https://global.discourse-cdn.com/wolfram/original/1X/eb87bc5c74a111313b1c5bbf64541504907a085b.png)

From this, we construct right and left x-t diagrams…

```
{imR, imL} = 
  Table[ImageResize[
    ImageCrop@
     ImageCrop[
      Image[Graphics[
        MapThread[
         plt[#1, 1, .15, .2, #2] &, {Range[-1.9, 2, .1], 
          Flatten@Table[{Black, White}, 20]}]], 
       ImageResolution -> 30], {125, 162}], {50, 
     50}], {plt, {edgedStripR, edgedStripL}}];
Row[{imR, imL}]

```

 ![2607xtleftright.png](https://global.discourse-cdn.com/wolfram/original/2X/5/52789462f2a0ff398ced35ee66b0d735a142aeb2.png)

…and convert them to the corresponding videos:

```
{vR, vL} = makeVideo /@ {imR, imL};
{goingR, goingL} = 
  Table[VideoFrameMap[
    ImagePad[#, 10, Padding -> Lighter[Gray, .25]] &, 
    v], {v, {vR, vL}}];
vv = VideoTimeStretch[GridVideo[{goingL, goingR}], 3]

```

![7429duoLR.gif](https://global.discourse-cdn.com/wolfram/original/3X/f/a/fa28ef706a667e46c362a7efc0a4fafdcc8dfb91.gif)

Many variations are now possible, only limited by our imagination:

![videoRL.gif](https://global.discourse-cdn.com/wolfram/original/3X/4/c/4cd0fb7aa6ced918bd83059bcdf367ac4c348f81.gif)

```
{vU, vD} = (VideoFrameMap[ImageRotate, #1] &) /@ {vR, vL};
videoRLUD = 
 VideoTimeStretch[
  GridVideo[{{vU, vR, vR, vR, vD}, {vU, vD, vL, vL, vD}, {vU, vD, 
     Missing[], vU, vD}, {vU, vD, vR, vU, vD}, {vU, vL, vL, vL, vD}}, 
   Spacings -> 5, Background -> Lighter[Gray, 0.5]], 2.5]

```

![videoLRUD.gif](https://global.discourse-cdn.com/wolfram/original/3X/d/2/d2e506c3a5fa5df17af12242402c8bbfc2a0d308.gif)

Some creativity can produce even more complicated examples. Adding color is one of those:

```
{vRc, vLc} = makeVideo /@ {imRc, imLc};
Table[VideoFrameMap[ImageResize[#, {50, 70}] &, v], {v, {vRc, vLc}}];
{goingRc, goingLc} = 
  Table[VideoFrameMap[ImagePad[#, 10, Padding -> LightGray] &, 
    v], {v, %}];
videoRc = 
  VideoFrameMap[ImageCompose[#, floor, Scaled[{.5, .125}]] &, goingRc];
videoLc = 
  VideoFrameMap[ImageCompose[#, floor, Scaled[{.5, .125}]] &, goingLc];
videoRLc = 
 VideoTimeStretch[GridVideo[{Table[videoRc, 5], Table[videoLc, 5]}], 
  1.5]

```

![videoRLc.gif](https://global.discourse-cdn.com/wolfram/original/2X/8/8b225dc55b80a76c08677e89c6418f977594ffa6.gif)

More complicated objects could be filled with “edged” strips and make illusions like the [Mario](https://twitter.com/jagarikin/status/1334689789438644224?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E1335266992228626432%7Ctwgr%5E%7Ctwcon%5Es3_&ref_url=https://jake.vision/blog/motion-illusions/) one mentioned above!

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [July 11, 2022, 1:39pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/2 "2022-07-11T13:39:48Z")

</div>

Fantastic! Thanks for sharing! Perhaps this could be implemented in some Wolfram function repository function? Have you thought about this?

---

<div class="post-metadata">

**Author:** ![wolframcommunity](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/wolframcommunity/32/8335_2.png) [@wolframcommunity](https://community.wolfram.com/u/wolframcommunity)\
**Post date:** [July 11, 2022, 1:53pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/3 "2022-07-11T13:53:08Z")

</div>

![news-congrads-kkluyshnik-02-04-19.jpg](https://global.discourse-cdn.com/wolfram/original/3X/6/a/6a310c2d0904616faf4e6e148260c9f29ab9f4eb.jpeg) – you have earned _ **Featured Contributor Badge** _ ![2015-11-02_10-07-11.png](https://global.discourse-cdn.com/wolfram/original/3X/5/0/50e59c9ead62f729e7130d3ea1482555a75602b6.png)  
Your exceptional post has been selected for our editorial column _ **Staff Picks** _ [http://wolfr.am/StaffPicks](http://wolfr.am/StaffPicks) and [Your Profile](http://community.wolfram.com/web/erikmahieu) is now distinguished by a _ **Featured Contributor Badge** _ and is displayed on the [Featured Contributor Board](https://community.wolfram.com/people). Thank you!

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [July 22, 2022, 8:35pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/4 "2022-07-22T20:35:31Z")

</div>

This is somewhat related to [this old post](https://wolfram.discourse.group/t/20110/1) - but better explained! Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![erikmahieu](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/erikmahieu/32/8091_2.png) [@erikmahieu](https://community.wolfram.com/u/erikmahieu)\
**Post date:** [July 23, 2022, 9:20am UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/5 "2022-07-23T09:20:47Z")

</div>

Sorry, Hendrik, I was not aware of your contribution. When I started with mine, I analysed the attached video (marioReversePhi.mp4) that inspired me. I also noticed the flashing colours and even tested alternative sequences other than te one used:

```
colors = 
  VideoMapList[
   Last@DominantColors[#Image, 2, {"Color", "Coverage"}] &, v];
repeatedColors = 
 RotateLeft[
  FindRepeat[colors[[All, 1]], 
   SameTest -> (Abs[#1[[1]] - #2[[1]]] < .05 &)], 0]

```

![7028ScreenShot2022-07-23at11.01.42.png](https://global.discourse-cdn.com/wolfram/original/3X/a/b/ab70ee9640fc764bdff05a770f7a230983ef15ec.png)

But I realised that neither the flashing nor the composition of the sequence was the main driver of this illusion. I converted the Mario video to grayscale and the illusion of motion was similar:

```
VideoFrameMap[ColorConvert[#, "Grayscale"] &, v]

```

![8276ezgif.com-gif-maker-6.gif](https://global.discourse-cdn.com/wolfram/original/3X/1/4/14b0941d8291343a3389954462b169f9678b5475.gif)

I think that the flashing and coloring may help but the main contribution to the illusion is the edge effect which I tried to explain above.  
I am working further on this while trying to answer Sander Huisman about his previous suggestion. I will be back on this very interesting visual effect!

---

<div class="post-metadata">

**Author:** ![naomielliott813](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/naomielliott813/32/18352_2.png) [@naomielliott813](https://community.wolfram.com/u/naomielliott813)\
**Post date:** [July 25, 2022, 9:24pm UTC](https://community.wolfram.com/t/visual-motion-illusions/20264/6 "2022-07-25T21:24:08Z")

</div>

It’s an interesting spacial illusion, and I can see how this sort of thing can be used to prevent accidents such as bumping into things, with a lot of application.
