Script done in collaboration with Jean Spezia.

TODO: describe what we do here...

In [ ]:
import os
In [ ]:
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'
vext = '.webm'
!ls -lR
In [ ]:
!mkdir -p results
In [ ]:
#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')
In [ ]:
N_orient, N_overlap = 8, 2
B_theta = 1.
In [ ]:
 
In [ ]:
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 [ ]:
print mov.max(), mov.min()
In [ ]:
mov_=mc.anim_save(mc.rectif(mov, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name)
In [ ]:
mov_=mc.anim_save(mc.rectif(mov_mask, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name)
In [ ]:
mov_=mc.anim_save(mc.rectif(mov/mov_mask, contrast=.99), os.path.join(mc.figpath, name))
mc.in_show_video(name)
In [ ]:
print mov_mask.max(), mov_mask.min()
In [ ]:
A = np.random.rand(5, 5)
print A
In [ ]:
mc.rectif(A, contrast=1, verbose=True)
In [ ]:
A
In [ ]:
N_orient, N_overlap = 8, 3
B_theta = 1.
In [ ]:
%%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 [ ]:
%%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 [ ]:
%%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 [ ]:
%%timeit -n1

diag1 = mc.envelope_gabor(fx, fy, ft)