{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Horizon" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Script done in collaboration with Jean Spezia.\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import MotionClouds as mc\n", "fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)\n", "seed = 1234\n", "size = 5\n", "N_X, N_Y, N_frame = 2**size, 2**size, 128\n", "\n", "mc.figpath = '../files/2015-02-19_horizon'\n", "if not(os.path.isdir(mc.figpath)): os.mkdir(mc.figpath)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fx, fy, ft = mc.get_grids(N_X, N_Y, N_frame)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "N_orient = 9\n", "hzn1 = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))\n", "for i, x_i in enumerate(np.linspace(-1, 1., N_orient)):\n", " for j, x_j in enumerate(np.linspace(-1, 1., N_orient)):\n", " V_X = 2 * x_i / (1+x_i**2)\n", " V_Y = 2 * x_j / (1+x_j**2)\n", " #f_0 = ...\n", " # theta = np.arctan2(V_Y, V_X)\n", " env = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)\n", " speed2 = mc.random_cloud(env, seed=seed)\n", " hzn1[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :] = speed2\n", "\n", "name = 'optic-flow'\n", "mc.anim_save(mc.rectif(hzn1, contrast=.99), os.path.join(mc.figpath, name))\n", "mc.in_show_video(name, figpath=mc.figpath)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "N_orient = 9\n", "hzn2 = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))\n", "i = 0\n", "j = 0\n", "while (i != 9):\n", " while (j != 9):\n", " hzn2[(i)*N_X:(i+1)*N_Y, (j)*N_Y:(j+1)*N_Y, :] = speed2\n", " j += 1\n", " j = 0\n", " i += 1\n", "\n", "V_X = 0.5\n", "V_Y = 0.0\n", "i = 3\n", "j = 0\n", "while (i != -1):\n", " env = mc.envelope_gabor(fx, fy, ft, V_X=-V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)\n", " speed = mc.random_cloud(env, seed=seed)\n", " env = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)\n", " speed2 = mc.random_cloud(env, seed=seed)\n", " while (j != 9):\n", " hzn2[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :] = speed\n", " hzn2[(8-i)*N_X:(9-i)*N_X, j*N_Y:(j+1)*N_Y, :] = speed2\n", " j += 1\n", " j = 0\n", " V_X = V_X + V_X*1.5\n", " V_Y = V_Y + V_Y*1.5\n", " i += -1 \n", "\n", "name = 'Horizon'\n", "mc.anim_save(mc.rectif(hzn1, contrast=.99), os.path.join(mc.figpath, name))\n", "mc.in_show_video(name, figpath=mc.figpath)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(0, 32, 128)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hzn = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))\n", "hzn[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :].shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hzn = hzn1 + hzn2\n", "dest = 'flow'\n", "mc.anim_save(mc.rectif(hzn, contrast=.99), dest)\n", "mc.in_show_video(name, figpath=mc.figpath)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## some book keeping for the notebook" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2018-11-07T16:19:23.177738Z", "start_time": "2018-11-07T16:19:23.125993Z" } }, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.1 64bit [Clang 10.0.0 (clang-1000.11.45.5)]" }, { "module": "IPython", "version": "7.1.1" }, { "module": "OS", "version": "Darwin 17.7.0 x86_64 i386 64bit" }, { "module": "numpy", "version": "1.15.4" }, { "module": "scipy", "version": "1.1.0" }, { "module": "matplotlib", "version": "3.0.1" }, { "module": "MotionClouds", "version": "20180606" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.1 64bit [Clang 10.0.0 (clang-1000.11.45.5)]
IPython7.1.1
OSDarwin 17.7.0 x86_64 i386 64bit
numpy1.15.4
scipy1.1.0
matplotlib3.0.1
MotionClouds20180606
Wed Nov 14 11:15:24 2018 CET
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.1 64bit [Clang 10.0.0 (clang-1000.11.45.5)] \\\\ \\hline\n", "IPython & 7.1.1 \\\\ \\hline\n", "OS & Darwin 17.7.0 x86\\_64 i386 64bit \\\\ \\hline\n", "numpy & 1.15.4 \\\\ \\hline\n", "scipy & 1.1.0 \\\\ \\hline\n", "matplotlib & 3.0.1 \\\\ \\hline\n", "MotionClouds & 20180606 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Wed Nov 14 11:15:24 2018 CET} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.1 64bit [Clang 10.0.0 (clang-1000.11.45.5)]\n", "IPython 7.1.1\n", "OS Darwin 17.7.0 x86_64 i386 64bit\n", "numpy 1.15.4\n", "scipy 1.1.0\n", "matplotlib 3.0.1\n", "MotionClouds 20180606\n", "Wed Nov 14 11:15:24 2018 CET" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%load_ext version_information\n", "%version_information numpy, scipy, matplotlib, MotionClouds" ] } ], "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.7.1" } }, "nbformat": 4, "nbformat_minor": 2 }