Generating textures with different complexities

This video shows different MotionClouds with different complexities, from a crystal-like Grating to textures with an incresing span of spatial frequencies (resp "Mc Narrow" and "MC Broad"). This is to illustrate the different stimuli used in this paper on the chracterization of speed-selectivity in the retina available @ https://www.nature.com/articles/s41598-018-36861-8 .



In [1]:
#initialize
import os
import numpy as np
import MotionClouds as mc

B_theta = 0.
B_V = mc.B_V/4
mc.N_frame = 128

fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)

mc.figpath = '../files/'
if not(os.path.isdir(mc.figpath)): os.mkdir(mc.figpath)
In [3]:
name = '2019-01-30_Ravello19'
vext = '.mp4'
name_ = os.path.join(mc.figpath, name)

seed = 123456
B_sfs = [0., 0.02, 0.2] 

im = np.empty(shape=(mc.N_X, mc.N_Y, 0))
for B_sf in B_sfs:
    if B_sf==0: # Grating
        im_new = np.sin(2*np.pi*(mc.sf_0*mc.N_X*(fx - .25*ft/mc.V_X)))
    else: # Motion Cloud
        im_new = mc.random_cloud(mc.envelope_gabor(fx, fy, ft, B_sf=B_sf, B_V=B_V, B_theta=B_theta), seed=seed)
    im_new = mc.rectif(im_new, method='energy')
    im = np.concatenate((im, im_new), axis=-1)

im = mc.rectif(im)

mc.anim_save(im, name_, vext=vext)
mc.in_show_video(name_, figpath=mc.figpath, vext=vext)

Annotating the movie using the (excellent) MoviePy library:

In [4]:
from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip

clip = [VideoFileClip(name_ + vext)]

t = 0
texts = ["Grating", "MC Narrow", "MC Broad"]
colors = ['blue', 'green', 'orange']

txt_opts = dict(fontsize=50, font="Amiri-Bold", stroke_color='gray', stroke_width=.5)
for text, color in zip(texts, colors):
    # Generate a text clip. You can customize the font, color, etc.
    txt_clip = TextClip(text, color=color, **txt_opts)
    # Say that you want it to appear 3s at the center of the screen
    txt_clip = txt_clip.set_start(t).set_pos('center').set_duration(3)
    t += clip[0].duration/len(texts)
    clip.append(txt_clip)

# Overlay the text clip on the first video clip
video = CompositeVideoClip(clip)

# Write the result to a file (many options available !)
video.write_videofile(name_ + '_text' + vext)
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
t:   1%|          | 28/2304 [00:00<00:08, 258.17it/s, now=None]
Moviepy - Building video ../files/2019-01-30_Ravello19_text.mp4.
Moviepy - Writing video ../files/2019-01-30_Ravello19_text.mp4

                                                                 
Moviepy - Done !
Moviepy - video ready ../files/2019-01-30_Ravello19_text.mp4

some book keeping for the notebook

In [5]:
%load_ext version_information
%version_information numpy, scipy, matplotlib, MotionClouds
Out[5]:
Software Version
Python 3.7.2 64bit [Clang 10.0.0 (clang-1000.11.45.5)]
IPython 7.2.0
OS Darwin 18.2.0 x86_64 i386 64bit
numpy 1.16.0
scipy 1.2.0
matplotlib 3.0.2
MotionClouds 20180606
Thu Jan 31 12:21:58 2019 CET