Tiling Motion Clouds
Script done in collaboration with Jean Spezia.
In [1]:
import os
In [2]:
import numpy as np
import MotionClouds as mc
size = 5
mc.N_X, mc.N_Y, mc.N_frame = 2**size, 2**size, 2**size
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
name = 'MotionPlaid'
mc.figpath = '../files/2015-02-19_MotionPlaid'
if not(os.path.isdir(mc.figpath)): os.mkdir(mc.figpath)
In [3]:
!mkdir -p results
In [4]:
#mask = 1 - np.abs(2*fx) - np.abs(2*fy)
#mask = 1.*(mask>0.)
#mask *= mask>0.
mask = 1 - np.max((np.abs(2*fx), np.abs(2*fy)), axis=0)
#mask = np.sqrt((2*fx)**2 + (2*fy)**2)
#mask = np.ones_like(fx)
print (mask.min(), mask.max(), mask.shape)
mov_=mc.anim_save(mask, os.path.join(mc.figpath, 'mask2'))
mc.in_show_video('mask2', figpath=mc.figpath)
In [5]:
N_orient, N_overlap = 8, 2
B_theta = 1.
In [6]:
mov = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
mov_mask = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
for i, theta1 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)[::-1]):
diag1 = mc.envelope_gabor(fx, fy, ft, theta=theta1, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_theta=B_theta)
for j, theta2 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)):
mov_ = np.zeros_like(mov)
mov_mask_ = np.zeros_like(mov)
diag2 = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta2), V_Y=np.sin(theta2), B_theta=B_theta)
#mov[(i)*mc.N_X:(i+1)*mc.N_X, (j)*mc.N_Y : (j+1)*mc.N_Y, :] = mc.random_cloud(diag1 + diag2, seed=1234)
mov_[:mc.N_X, :mc.N_Y, :] = mc.random_cloud(diag1 + diag2, seed=1234)*mask
mov_mask_[:mc.N_X, :mc.N_Y, :] = mask
#mov_[:mc.N_X, :mc.N_Y, :] = mask
mov_ = np.roll(mov_, i*mc.N_X//N_overlap, axis=0)
mov_ = np.roll(mov_, j*mc.N_Y//N_overlap, axis=1)
mov += mov_
mov_mask_ = np.roll(mov_mask_, i*mc.N_X//N_overlap, axis=0)
mov_mask_ = np.roll(mov_mask_, j*mc.N_Y//N_overlap, axis=1)
#print mov_mask_.max(), mov_mask_.min()
mov_mask += mov_mask_
In [7]:
print (mov.max(), mov.min())
In [8]:
mov_=mc.anim_save(mc.rectif(mov, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name, figpath=mc.figpath)
In [9]:
mov_=mc.anim_save(mc.rectif(mov_mask, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name, figpath=mc.figpath)
In [10]:
mov_=mc.anim_save(mc.rectif(mov/mov_mask, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name, figpath=mc.figpath)
In [11]:
print (mov_mask.max(), mov_mask.min())
In [12]:
A = np.random.rand(5, 5)
In [13]:
mc.rectif(A, contrast=1, verbose=True)
Out[13]:
In [14]:
A
Out[14]:
In [15]:
N_orient, N_overlap = 8, 3
B_theta = 1.
In [16]:
%%timeit -n1
mov = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
for i, theta1 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)[::-1]):
diag1 = mc.envelope_gabor(fx, fy, ft, theta=theta1, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_theta=B_theta)
for j, theta2 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)):
mov_ = np.zeros_like(mov)
diag2 = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta2), V_Y=np.sin(theta2), B_theta=B_theta)
#mov[(i)*mc.N_X:(i+1)*mc.N_X, (j)*mc.N_Y : (j+1)*mc.N_Y, :] = mc.random_cloud(diag1 + diag2, seed=1234)
mov_[:mc.N_X, :mc.N_Y, :] = mc.random_cloud(diag1 + diag2, seed=1234)
#mov_[:mc.N_X, :mc.N_Y, :] = mask
mov_ = np.roll(mov_, i*mc.N_X//N_overlap, axis=0)
mov_ = np.roll(mov_, j*mc.N_Y//N_overlap, axis=1)
mov += mov_
In [17]:
%%timeit -n1
mov = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
for i, theta1 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)[::-1]):
diag1 = mc.envelope_gabor(fx, fy, ft, theta=theta1, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_theta=B_theta)
mov_ = np.zeros_like(mov)
mov_[:mc.N_X, :mc.N_Y, :] = mc.random_cloud(diag1, seed=1234)
for j, theta2 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)):
mov += np.roll(mov_, j*mc.N_Y//N_overlap, axis=1)
for j, theta2 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)):
diag2 = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta2), V_Y=np.sin(theta2), B_theta=B_theta)
mov_ = np.zeros_like(mov)
mov_[:mc.N_X, :mc.N_Y, :] = mc.random_cloud(diag2, seed=1234)
for i, theta1 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)[::-1]):
mov += np.roll(mov_, i*mc.N_X//N_overlap, axis=0)
In [18]:
%%timeit -n1
mov = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
mov1 = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
mov2 = mc.np.zeros(((N_orient*mc.N_X), (N_orient*mc.N_X), mc.N_frame))
for i, theta1 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)[::-1]):
diag1 = mc.envelope_gabor(fx, fy, ft, theta=theta1, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_theta=B_theta)
mov_ = np.zeros_like(mov)
mov_[:mc.N_X, :mc.N_Y, :] = mc.random_cloud(diag1, seed=1234)
mov1 += np.roll(mov_, i*mc.N_X//N_overlap, axis=0)
mov2 += np.roll(mov_, i*mc.N_Y//N_overlap, axis=1)
for j, theta2 in enumerate(np.linspace(0, 2*np.pi, N_orient*N_overlap, endpoint=False)):
mov1 += np.roll(mov1, j*mc.N_Y//N_overlap, axis=1)
mov2 += np.roll(mov2, j*mc.N_Y//N_overlap, axis=0)
mov = mov1 + mov2
In [19]:
%%timeit -n1
diag1 = mc.envelope_gabor(fx, fy, ft)
some book keeping for the notebook¶
In [20]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, MotionClouds
Out[20]: