{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Testing the Speed" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A moving pattern (stimulus/image) can be thought as a set of pixels and\n", "that each pixel intensities are translated from one frame to the next\n", "frame (the intensities, not the pixel:\n", "\n", "I(**x**,t)=I(**x**+**u**,t+1); space is a vector with coordinates\n", "(x1,x2)’ and time is *t*. **u**=(u1,u2) is the 2D velocity. Motion\n", "Clouds represent 2D + t images. **x**(t), each pixel follows a 2D path\n", "as a function of time. So we have a space-time function f(**x**,t) by\n", "translating a 2D signal f0(**x**) with velocity **u, i.e,**\n", "f(**x**,t)=f0(**x**-**u**t).\n", "\n", "The Fourier transform of such a function is\n", "\n", "F(wx, wy, wt)=F0(wx,wy) \\\\delta(u1wx + u2wy + wt)\n", "\n", "F0 is the 2D transform of f0 and \\\\delta is the dirac delta. The energy\n", "spectrum is nonzero on a plane whose orientation gives the velocity.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "np.set_printoptions(precision=3, suppress=True)\n", "import pylab\n", "import matplotlib.pyplot as plt\n", "#!rm -fr ../files/speed*" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function envelope_speed in module MotionClouds:\n", "\n", "envelope_speed(fx, fy, ft, V_X=1.0, V_Y=0.0, B_V=0.5)\n", " Returns the speed envelope:\n", " selects the plane corresponding to the speed ``(V_X, V_Y)`` with some bandwidth ``B_V``.\n", " \n", " * (V_X, V_Y) = (0,1) is downward and (V_X, V_Y) = (1, 0) is rightward in the movie.\n", " * A speed of V_X=1 corresponds to an average displacement of 1/N_X per frame.\n", " To achieve one spatial period in one temporal period, you should scale by\n", " V_scale = N_X/float(N_frame)\n", " If N_X=N_Y=N_frame and V=1, then it is one spatial period in one temporal\n", " period. It can be seen along the diagonal in the fx-ft face of the MC cube.\n", " \n", " A special case is used when ``B_V=0``, where the ``fx-ft`` plane is used as\n", " the speed plane: in that case it is desirable to set ``(V_X, V_Y)`` to ``(0, 0)``\n", " to avoid aliasing problems.\n", " \n", " Run the 'test_speed' notebook to explore the speed parameters, see\n", " http://motionclouds.invibe.net/posts/testing-speed.html\n", "\n" ] } ], "source": [ "import MotionClouds as mc\n", "name = 'speed'\n", "fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)\n", "help(mc.envelope_speed)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# explore parameters\n", "for V_X in [-1.0, -0.5, 0.0, 0.1, 0.5, 1.0, 4.0]:\n", " name_ = name + '-V_X-' + str(V_X).replace('.', '_')\n", " z = mc.envelope_gabor(fx, fy, ft, V_X=V_X)\n", " mc.figures(z, name_)\n", " mc.in_show_video(name_)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for V_Y in [-1.0, -0.5, 0.5, 1.0, 2.0]:\n", " name_ = name + '-V_Y-' + str(V_Y).replace('.', '_')\n", " z = mc.envelope_gabor(fx, fy, ft, V_X=0.0, V_Y=V_Y)\n", " mc.figures(z, name_)\n", " mc.in_show_video(name_)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for B_V in [0, 0.001, 0.01, 0.05, 0.1, 0.5, 1.0, 10.0]:\n", " name_ = name + '-B_V-' + str(B_V).replace('.', '_')\n", " z = mc.envelope_gabor(fx, fy, ft, B_V=B_V)\n", " mc.figures(z, name_)\n", " mc.in_show_video(name_)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 0 }