cv2.PCABackProject
Rebuild the original data from its principal components
- data
- mean
- eigenvectors
- nparray
The inverse of PCAProject. You've got data living in principal-component coordinates - N x K, the output of a projection or a truncated version of it - and you want it back in the original feature space. That's this: multiply by the eigenvectors, add the mean back, and you're in N x M again.
If you kept every eigenvector, this is a clean round trip and you get your data back. If you dropped some, you get the best reconstruction possible from the components you kept - which is the whole point, because the difference between the two arrays is your reconstruction error, and that's a number you can act on.
Inputs
Three NPARRAY sockets, all required:
data- the projected matrix,N x K. K must match the number of eigenvectors you feed in; if you trimmed columns somewhere between project and back-project, both numbers must agree or cv2 raises.mean- the same mean that came out of thePCACompute/PCACompute2run,1 x M. cv2 adds this back, so a wrong or zero mean offsets every reconstructed sample; nothing raises, the numbers are just shifted. Wire it from the compute node.eigenvectors-K x M, again from the same run. This is the basis, and it has to be the basis your data was expressed in.
One output: nparray, N x M.
The model arrays are the contract. Mean from one run with eigenvectors from another produces perfectly finite, entirely meaningless output - the same trap as PCAProject, just in reverse, and slightly nastier because the result looks like real data.
What it's for
Reconstruction error / anomaly detection. Project into the components that matter, back-project, and compare with the original. Small residual means your data is genuinely in the subspace you kept; a big residual means it isn't, which is how PCA-based anomaly detection works in practice - the outlier has structure the principal components don't explain. Do the comparison with the pack's own arithmetic wrappers (cv2.absdiff, cv2.norm, CV Array Statistic on the difference) rather than by eye.
Denoising. This is the same operation with a friendlier name. Components you discard carry mostly noise, so the round trip through a truncated basis is a low-pass filter fitted to your specific data. For a cloud of points or a set of descriptors, PCACompute with retainedVariance at 0.95, then PCAProject, then this node, gives you back a cleaned version. Cheap, deterministic, no model.
Visualising what a component means. Back-project a vector that is all zeros except a 1 in one component: what comes back is that eigenvector scaled to the original units, which is how you look at "what is component 3 telling me" as actual data.
Getting into a different pipeline's coordinate system. If some other tool hands you PCA-space data and a mean/eigenvector pair from its own run, this node is the decoder ring - Parse Matrix types the vectors in, and you're back in pixel or feature units.
Honestly, a small node in a small family
Four PCA wrappers exist in this pack, and this is the one people reach for least. PCACompute, PCACompute2, PCAProject, this. If you're doing the usual "reduce these features before a classifier" job, you'll stop at project and never come here. Come back for the round trip - reconstruction error and denoising - and don't expect the pack's curated nodes to cover it: PCA is exposed as raw wrappers only, with no curated node bridging it, which tells you how rarely the author needed it in their own pipelines.
The dtype rules are the same as the rest of the family: float32 or float64 throughout, via CV Cast Array if you're not already there. No batch handling - a linked image gives you frame 0, one array out.
Installing
ComfyUI Manager → search ComfyUI CV → Install → restart:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Python ≥ 3.12 and a recent ComfyUI - the pack is built on ComfyUI's V3 node API, and its ~470 raw wrappers are generated at import from the symbols your installed cv2 exposes. This one is core cv2 (PCABackProject), so it needs no contrib wheel and no model files.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| data | NPARRAY | - - - A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here. | |
| mean | NPARRAY | - - - A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here. | |
| eigenvectors | NPARRAY | - - - A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |