.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/introduction/demo_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_introduction_demo_example.py: ======================================= Using the motion energy pyramid class ======================================= This example shows how to extract motion energy features from a video. First, we need to define the video we want to use. In this example, we'll use a small video. The video is 2.5 minutes in duration with a frame rate of 24fps. For the purposes of this example, we'll only use the first 200 frames. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: default nimages = 200 stimulus_fps = 24 video_file = 'http://anwarnunez.github.io/downloads/avsnr150s24fps_tiny.mp4' .. GENERATED FROM PYTHON SOURCE LINES 16-22 .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 24-25 The video is RGB. So, the first step is to convert it to a luminance representation. Internally, this is achieved by converting RGB pixel values to CIE-LAB pixel values and keeping only the "L" channel. The function :func:`moten.io.video2luminance` takes care of downloading the video, converting RGB to luminance, and spatial downsampling if needed. .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: default import moten import matplotlib.pyplot as plt luminance_images = moten.io.video2luminance(video_file, nimages=nimages) nimages, vdim, hdim = luminance_images.shape .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/scipy/__init__.py:137: UserWarning: NumPy 1.16.5 or above is required for this version of SciPy (detected version 1.16.4) UserWarning) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Next we need to construct the motion energy pyramid. To achieve this, we must provide the size of the stimulus frames in pixels (``vdim`` and ``hdim``) and also the frame rate .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: default pyramid = moten.pyramids.MotionEnergyPyramid(stimulus_vhsize=(vdim, hdim), stimulus_fps=stimulus_fps) print(pyramid) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-41 Finally, we use the method ``project_stimulus`` to compute the motion energy features (see :meth:`moten.pyramids.MotionEnergyPyramid.project_stimulus`). .. GENERATED FROM PYTHON SOURCE LINES 41-47 .. code-block:: default features = pyramid.project_stimulus(luminance_images) print(features.shape) fig, ax = plt.subplots(figsize=(12, 12)) ax.matshow(features, aspect='auto') plt.show() .. image:: /auto_examples/introduction/images/sphx_glr_demo_example_001.png :alt: demo example :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none (200, 2530) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 42.264 seconds) .. _sphx_glr_download_auto_examples_introduction_demo_example.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_