OpenCV PCABackProject_0
Reconstructing data (and images) from a few components
- data
- mean
- eigenvectors
- result
- nparray
If you've ever seen the "eigenfaces" demos - a face reconstructed from a handful of principal components, each one adding a little more fidelity - you've seen what PCABackProject_0 does. It's the inverse of PCAProject: it takes data that has been compressed into a low-dimensional PCA subspace and rebuilds it back into the original space. In this pack, that means you can genuinely do lossy PCA compression on image patches or feature vectors inside ComfyUI, or manipulate data while it's in a compact form and then expand it again.
Honest framing: this is real computer vision, not diffusion. You reach for it when you're porting a Python/OpenCV pipeline into a graph, or when you want deterministic, millisecond dimensionality tricks rather than a generative model. Which is exactly what this pack is for.
How it works
cv2.PCABackProject(data, mean, eigenvectors) performs the PCA inverse transformation: the input data (the projected coefficients, one row per sample) is multiplied back through eigenvectors, and mean is added back on. Roughly:
reconstructed = data @ eigenvectors + mean
It's the exact inverse of PCAProject's (data - mean) @ eigenvectors.T, so the two round-trip cleanly. mean and eigenvectors come straight from a PCACompute or PCACompute2 call - that's the natural pipeline:
PCACompute_0on your raw data learnsmean+eigenvectorsPCAProject_0compresses a sample into a few coefficients- (optional) tweak the coefficients, e.g. zero out the weak components
PCABackProject_0reconstructs - you've effectively low-pass filtered the data, which is a classic PCA denoise/compression move
The inputs that matter
data(NPARRAY) - the compressed coefficients to expand, one sample per row.meanandeigenvectors(NPARRAY) - the PCA model fromPCACompute_0/PCACompute2_0. Reuse the exact ones that produceddata, or the reconstruction drifts.result(NPARRAY, optional) - an out-parameter from OpenCV's signature; you can ignore it. The node always returns the reconstruction.
Output: nparray - same shape as data but back in the original feature space. Feed it to Nparrays2Image if your rows were flattened image patches.
How to install it
Pack-level install, once:
- ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
- Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Requires opencv-contrib-python (README says pip install opencv-python-contrib; same package, alias name). No model files.
Common issues & troubleshooting
- Shape mismatch is the #1 error.
data,mean, andeigenvectorsmust agree: columns ofdatamust equal rows ofeigenvectors, andmeanmust be 1 row with the original dimension count. If you get a(-215:Assertion failed)it's almost always this - check the OpenCV docs forPCABackProject's expected shapes. - Remember the pack's batch rule. Only
batch_size==1; pull one frame withImageFromBatchifImage2Nparraycomplains. - Don't mix
_0and_1PCA nodes mid-pipeline. They're identical wrappers (MatLike vs UMat overloads), so mixing is harmless - but keep one consistent path so you're not confused about which model you're using.
The name is a mouthful, but the concept is one line: compress with PCAProject, reconstruct with PCABackProject. Everything else is just shapes.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| data | NPARRAY | — | |
| mean | NPARRAY | — | |
| eigenvectors | NPARRAY | — | |
| resultopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |