PCA

The pca() function performs spectral dimensionality reduction on a DataCube by computing its principal components. It decomposes the spectral signatures into orthogonal axes ordered by variance, then projects each pixel’s spectrum onto the first N components.

Example

The following example demonstrates PCA on a synthetically generated :class:DataCube, extracting the first three principal components.

 1import wizard
 2from wizard._processing.cluster import pca
 3from wizard._utils.example import generate_pattern_stack
 4
 5data = generate_pattern_stack(50, 200, 200, n_circles=2, n_rects=2, n_triangles=2)
 6dc = wizard.DataCube(data)
 7
 8# reduce to 10 components
 9dc_reduced = pca(dc, n_components=10)
10print("Reduced cube shape:", dc_reduced.cube.shape)

Output:

Reduced cube shape: (10, 200, 200)