An optic flow with Motion Clouds
Horizon¶
Script done in collaboration with Jean Spezia.
In [1]:
import os
import numpy as np
import MotionClouds as mc
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
seed = 1234
size = 5
N_X, N_Y, N_frame = 2**size, 2**size, 128
mc.figpath = '../files/2015-02-19_horizon'
if not(os.path.isdir(mc.figpath)): os.mkdir(mc.figpath)
In [2]:
fx, fy, ft = mc.get_grids(N_X, N_Y, N_frame)
In [3]:
N_orient = 9
hzn1 = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))
for i, x_i in enumerate(np.linspace(-1, 1., N_orient)):
for j, x_j in enumerate(np.linspace(-1, 1., N_orient)):
V_X = 2 * x_i / (1+x_i**2)
V_Y = 2 * x_j / (1+x_j**2)
#f_0 = ...
# theta = np.arctan2(V_Y, V_X)
env = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)
speed2 = mc.random_cloud(env, seed=seed)
hzn1[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :] = speed2
name = 'optic-flow'
mc.anim_save(mc.rectif(hzn1, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name, figpath=mc.figpath)
In [4]:
N_orient = 9
hzn2 = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))
i = 0
j = 0
while (i != 9):
while (j != 9):
hzn2[(i)*N_X:(i+1)*N_Y, (j)*N_Y:(j+1)*N_Y, :] = speed2
j += 1
j = 0
i += 1
V_X = 0.5
V_Y = 0.0
i = 3
j = 0
while (i != -1):
env = mc.envelope_gabor(fx, fy, ft, V_X=-V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)
speed = mc.random_cloud(env, seed=seed)
env = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf)
speed2 = mc.random_cloud(env, seed=seed)
while (j != 9):
hzn2[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :] = speed
hzn2[(8-i)*N_X:(9-i)*N_X, j*N_Y:(j+1)*N_Y, :] = speed2
j += 1
j = 0
V_X = V_X + V_X*1.5
V_Y = V_Y + V_Y*1.5
i += -1
name = 'Horizon'
mc.anim_save(mc.rectif(hzn1, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name, figpath=mc.figpath)
In [5]:
hzn = mc.np.zeros((N_orient*N_X, N_orient*N_X, N_frame))
hzn[i*N_X:(i+1)*N_X, j*N_Y:(j+1)*N_Y, :].shape
Out[5]:
In [6]:
hzn = hzn1 + hzn2
dest = 'flow'
mc.anim_save(mc.rectif(hzn, contrast=.99), dest)
mc.in_show_video(name, figpath=mc.figpath)
some book keeping for the notebook¶
In [7]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, MotionClouds
Out[7]: