An optic flow with Motion Clouds

Horizon

Script done in collaboration with Jean Spezia.

TODO: describe what we do here...

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
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)
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)
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]:
(0, 32, 128)
In [6]:
hzn = hzn1 + hzn2
dest = 'flow'
mc.anim_save(mc.rectif(hzn, contrast=.99), dest)
mc.in_show_video(name)

Comments

Comments powered by Disqus