shape¶
Active Shape Model (ASM) and Principal Component Analysis (PCA).
This module provides functionalities to learn the characteristic shapes of tracked objects from training data.
- class ActiveShapeModel[source]¶
Bases:
objectConstructs and manages an Active Shape Model in 2D.
- Variables:
mean_shape (np.ndarray | None) – The mean vector of the aligned training shapes.
eigenvectors (np.ndarray | None) – The principal modes of shape variation.
eigenvalues (np.ndarray | None) – The variance explained by each principal component.
- fit(training_data, ref_type='mean')[source]¶
Align training shapes and compute the shape model.
- Parameters:
training_data (
list[ndarray]) – List of N x 2 arrays representing contour vertices.ref_type (
str) – Alignment reference, either “mean” or “first”. Defaults to “mean”.
- Return type:
None
Examples
>>> import numpy as np >>> from super_slurpy.shape import ActiveShapeModel >>> model = ActiveShapeModel() >>> shapes = [np.random.rand(20, 2) for _ in range(5)] >>> model.fit(training_data=shapes, ref_type="mean")
- perform_pca(data_matrix)[source]¶
Perform Principal Component Analysis using SVD.
- Parameters:
data_matrix (
ndarray) – M x N matrix with M the vector length and N the datasets.- Returns:
Eigenvalues, Eigenvectors, and the mean vector.
- Return type:
tuple[ndarray,ndarray,ndarray]
Examples
>>> import numpy as np >>> from super_slurpy.shape import perform_pca >>> data = np.random.rand(10, 5) >>> evals, evecs, mean_vec = perform_pca(data_matrix=data)