Skip to content

Principal component analysis

Algorithm atlasMachine learning

Find orthogonal directions that explain the greatest variance in centred data.

Try it on your image ↓

VISUAL WALKTHROUGHMachine learning
REFERENCE INPUTCorrelated features

The observations vary mainly along a diagonal direction.

RESULTKeep one principal coordinate

Two-dimensional observations become one scalar per sample. Variation perpendicular to the chosen axis is discarded.

STEP 03 / 03

Project samples onto the retained directions.

Mean, covariance direction and projections are computed from the displayed samples.

Try it on an image

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

Project BGR colour vectors into fewer principal components, then reconstruct the image. Components are learned from this image’s colour distribution.

The engine loads on your first run. Your images stay in this browser.

Input448 × 320
OutputWaiting for a result

Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.

Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Reduce descriptor dimensionality, compress correlated features or visualize a dataset.

How it works

  1. 01Subtract the training mean.
  2. 02Find covariance eigenvectors ordered by explained variance.
  3. 03Project samples onto the retained directions.

projection = (sample − mean) · retained basis

What to tune

maxComponents or retainedVariance selects dimensionality. Scale heterogeneous features before fitting when units differ.

Where it breaks down

Large variance is not always task-relevant information. Use the training mean and basis consistently on later data.

TypeScript API

Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.

All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.