4
$\begingroup$

the direction picture is

In version 11.0.1,I notice a new function ImageDisplacements perhaps can do this,but maybe I miss something:

pics = Import["https://i.stack.imgur.com/TW75w.gif"];
Show[First[pics], 
 ListStreamPlot[#, 
    DataRange -> (PadLeft[#, 2] & /@ 
       List /@ ImageDimensions[First[pics]]), VectorStyle -> Red] & /@
   ImageDisplacements[pics]]

Poor effect..

Updata for material

The gif just have three frame,so I upload a gif maybe is more suitable of this task: enter image description here

You also can get is by this code:

Export["test.gif", 
 ExampleData /@ 
  ExampleData[{"TestAnimation", "ToyVehicles"}, "Frames"], 
 "DisplayDurations" -> .5]
$\endgroup$
  • $\begingroup$ I threw on code-request because I feel that this calls for nontrivial development. $\endgroup$ – Mr.Wizard Dec 20 '16 at 23:52
  • $\begingroup$ @Mr.Wizard Thanks for edit. :) $\endgroup$ – yode Dec 21 '16 at 4:40
5
$\begingroup$

The problem is that ListStreamPlot expects the data array in a different order than it is arranged in an Image. You have to Transpose@*Reverse it:

flow = ImageDisplacements[pics];
ListStreamPlot[Transpose@Reverse@flow[[1]], 
 StreamPoints -> Fine, StreamColorFunction -> "CMYKColors"]

enter image description here

flow[[1]] is the flow from the first frame to the second frame. Replace it with flow[[2]] to visualize the flow from the second to the third.

$\endgroup$
  • $\begingroup$ How was flow defined? $\endgroup$ – J. M. will be back soon Dec 21 '16 at 1:08
  • $\begingroup$ @J.M.: Whoops, fixed. $\endgroup$ – Rahul Dec 21 '16 at 1:10
  • $\begingroup$ So this is just a first frame to second frame? $\endgroup$ – yode Dec 21 '16 at 3:12
  • $\begingroup$ @yode: "flow[[1]] is the flow from the first frame to the second frame. Replace it with flow[[2]] to visualize the flow from the second to the third." $\endgroup$ – Rahul Dec 21 '16 at 3:31
  • 1
    $\begingroup$ @yode: Then call ImageDisplacements with a list containing only the first and last frame. $\endgroup$ – Rahul Dec 21 '16 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.