motion

Motion Model and Particle Filter Tracking.

This module provides the statistical motion modeling and the particle filter implementation for contour tracking.

class MotionModel[source]

Bases: object

Creates a motion model from sequential state variations.

Variables:
  • variance (np.ndarray | None) – Standard deviation of the state differences.

  • correlation (np.ndarray | None) – Correlation coefficient matrix of the state differences.

__init__()[source]
fit(state_vectors)[source]

Compute the variance and correlation of state changes.

Parameters:

state_vectors (ndarray) – M x F matrix where M is the state dimension and F is the number of frames.

Return type:

None

Examples

>>> import numpy as np
>>> from super_slurpy.motion import MotionModel
>>> model = MotionModel()
>>> states = np.random.rand(5, 10)
>>> model.fit(state_vectors=states)
run_particle_filter(base_contour, num_particles, noise_scale)[source]

Generate perturbed contours for particle filter evaluation.

Parameters:
  • base_contour (ndarray) – The N x 2 array of the current contour vertices.

  • num_particles (int) – The number of particles (contours) to generate.

  • noise_scale (float) – Multiplier for the random noise applied to particles.

Returns:

A list of perturbed contour arrays.

Return type:

list[ndarray]

Examples

>>> import numpy as np
>>> from super_slurpy.motion import run_particle_filter
>>> contour = np.random.rand(20, 2)
>>> particles = run_particle_filter(
...     base_contour=contour,
...     num_particles=5,
...     noise_scale=1.0,
... )