Extract motion energy features from video using spatio-temporal Gabors
Project description
What is pymoten?
pymoten is a python package that provides a convenient way to extract motion energy features from video using a pyramid of spatio-temporal Gabor filters [1] [2]. The filters are created at multiple spatial and temporal frequencies, directions of motion, x-y positions, and sizes. Each filter quadrature-pair is convolved with the video and their activation energy is computed for each frame. These features provide a good basis to model brain responses to natural movies [3] [4].
Installation
Using pip, install the latest version from git:
pip install git+https://github.com/gallantlab/pymoten.git
Or the most recent release:
pip install pymoten
Getting started
Example using synthetic data
import moten
import numpy as np
# Generate synthetic data
nimages, vdim, hdim = (100, 90, 180)
noise_movie = np.random.randn(nimages, vdim, hdim)
# Create a pyramid of spatio-temporal gabor filters
pyramid = moten.get_default_pyramid(vhsize=(vdim, hdim), fps=24)
# Compute motion energy features
moten_features = pyramid.project_stimulus(noise_movie)
Simple example using a video file
import moten
# Stream and convert the RGB video into a sequence of luminance images
video_file = 'http://anwarnunez.github.io/downloads/avsnr150s24fps_tiny.mp4'
luminance_images = moten.io.video2luminance(video_file, nimages=100)
# Create a pyramid of spatio-temporal gabor filters
nimages, vdim, hdim = luminance_images.shape
pyramid = moten.get_default_pyramid(vhsize=(vdim, hdim), fps=24)
# Compute motion energy features
moten_features = pyramid.project_stimulus(luminance_images)
GPU acceleration
pymoten supports multiple computational backends. By default it runs on the CPU with NumPy, but it can also run on the GPU using PyTorch, which is much faster for large stimuli. The available backends are "numpy" (default), "torch", "torch_cuda" (NVIDIA GPUs), and "torch_mps" (Apple Silicon GPUs). The torch backends require PyTorch to be installed.
import moten
from moten.backend import set_backend
# Switch to a GPU backend (returns the backend module)
backend = set_backend("torch_cuda")
pyramid = moten.get_default_pyramid(vhsize=(vdim, hdim), fps=24)
# Move the stimulus onto the GPU, project, then bring the result back
stimulus_gpu = backend.asarray(luminance_images)
moten_features = pyramid.project_stimulus_batched(stimulus_gpu)
moten_features = backend.to_numpy(moten_features)
See the examples gallery for a complete walkthrough.
Cite as
Nunez-Elizalde AO, Deniz F, Dupré la Tour T, Visconti di Oleggio Castello M, and Gallant JL (2021). pymoten: scientific python package for computing motion energy features from video. Zenodo. https://doi.org/10.5281/zenodo.6349625
References
A MATLAB implementation can be found here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymoten-0.1.2.tar.gz.
File metadata
- Download URL: pymoten-0.1.2.tar.gz
- Upload date:
- Size: 62.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40632fb37276c77fadf986c0bba0806f6e27f5ed1764b1c5ab50a476170afda6
|
|
| MD5 |
8069bea0de6ba33dfe355f245cc7836c
|
|
| BLAKE2b-256 |
f5841bd2362fa0e63cccd0c5e368a415794320f4944a3206d41094f1442f8c15
|
Provenance
The following attestation bundles were made for pymoten-0.1.2.tar.gz:
Publisher:
publish_to_pypi.yml on gallantlab/pymoten
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymoten-0.1.2.tar.gz -
Subject digest:
40632fb37276c77fadf986c0bba0806f6e27f5ed1764b1c5ab50a476170afda6 - Sigstore transparency entry: 1671320304
- Sigstore integration time:
-
Permalink:
gallantlab/pymoten@4d78c7d605ae21cd0f018058379f84bf512e053f -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/gallantlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@4d78c7d605ae21cd0f018058379f84bf512e053f -
Trigger Event:
release
-
Statement type:
File details
Details for the file pymoten-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pymoten-0.1.2-py3-none-any.whl
- Upload date:
- Size: 53.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f70f28297a2dc0a26bd334f116e16c104962143662b70910a967e7aa0f3ff925
|
|
| MD5 |
4d0ec4ebda9b7ec5a2dbaec59a12f42d
|
|
| BLAKE2b-256 |
6f60db201618cf13bb4cc5c9b4307d23dc4a81a539c86828050935ee7d6770da
|
Provenance
The following attestation bundles were made for pymoten-0.1.2-py3-none-any.whl:
Publisher:
publish_to_pypi.yml on gallantlab/pymoten
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymoten-0.1.2-py3-none-any.whl -
Subject digest:
f70f28297a2dc0a26bd334f116e16c104962143662b70910a967e7aa0f3ff925 - Sigstore transparency entry: 1671320388
- Sigstore integration time:
-
Permalink:
gallantlab/pymoten@4d78c7d605ae21cd0f018058379f84bf512e053f -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/gallantlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@4d78c7d605ae21cd0f018058379f84bf512e053f -
Trigger Event:
release
-
Statement type: