Testing basic functions of Motion Clouds
Motion Clouds: raw principles¶
Motion Clouds are synthesized textures which aim at having similar characteristics as natural images but with controlled parameters. There are many ways to achieve these results and this notebook aims at showing that different procedures from different communities (neurioscience, modelling, computer vision, ...) may produce similar results.
In [1]:
import numpy as np
np.set_printoptions(precision=3, suppress=True)
import pylab
import matplotlib.pyplot as plt
%matplotlib inline
Using Fourier ("official Motion Clouds")¶
In [2]:
import MotionClouds as mc
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
Using mixtures of images¶
In [3]:
from scipy.misc import face
lena = face()
print(lena.shape)
lena = lena[:, (1024-768):, :].mean(axis=-1)
print(lena.shape)
lena -= lena.mean()
lena /= lena.std()
print(lena.shape)
In [4]:
plt.imshow(lena, cmap=plt.cm.gray)
Out[4]:
In [5]:
lena.shape
Out[5]:
In [6]:
lena[0, :]
Out[6]:
In [7]:
def noise(image=lena):
for axis in [0, 1]:
image = np.roll(image, np.random.randint(image.shape[axis]), axis=axis)
return image
In [8]:
plt.imshow(noise(), cmap=plt.cm.gray)
Out[8]:
In [9]:
plt.imshow(noise(), cmap=plt.cm.gray)
Out[9]:
Using ARMA processes¶
Now, we define the ARMA process as an averaging process with a certain time constant $\tau=30.$ (in frames).
In [10]:
def ARMA(image, tau=30.):
image = (1 - 1/tau)* image + 1/tau * noise()
return image
initializing
In [11]:
image = ARMA(lena)
plt.imshow(image, cmap=plt.cm.gray)
Out[11]:
In [12]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
Out[12]:
In [13]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
Out[13]:
In [14]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
Out[14]:
In [15]:
N_frame = 1024
z = np.zeros((lena.shape[0], lena.shape[1], N_frame))
z[:, :, 0] = image
for i_frame in range(1, N_frame):
z[:, :, i_frame] = ARMA(z[:, :, i_frame-1])
In [16]:
import os
name='arma'
mc.anim_save(.5 + .5*z, filename=os.path.join(mc.figpath, name))
mc.in_show_video(name)
In [17]:
"""
Averaging over multiple clouds
TODO: force the phase by setting the luminance at some point and averaging over multiple instances
(c) Laurent Perrinet - INT/CNRS
"""
import MotionClouds as mc
import numpy as np
import os
name = 'concentric'
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
seed = 123456
im = np.zeros((mc.N_X, mc.N_Y, mc.N_frame))
N = 20
for i_N in range(N):
im_ = mc.rectif(mc.random_cloud(mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0., B_theta=np.pi/4), seed=seed+i_N))
if i_N == 0:
phase = 0.5 + 0. * im_[0, 0, :]#mc.N_X/2, mc.N_Y/2, :]
#im += im_ - im_[mc.N_X/2, mc.N_Y/2, :] + phase
im += im_ - im_[0, 0, :] + phase
mc.anim_save(mc.rectif(im), os.path.join(mc.figpath, name))
mc.in_show_video(name)
In [18]: