Nodes/opencv-comfyui/OpenCV SVDecomp_0
ComfyUI Node

OpenCV SVDecomp_0

Singular value decomposition, if you ever need to factor a matrix

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV SVDecomp_0
  • src
  • w
  • u
  • vt
  • nparray_0
  • nparray_1
  • nparray_2
flags

SVDecomp_0 computes the singular value decomposition of a matrix: it factors an input into U·W·Vᵀ, where W holds the singular values and U, V are orthonormal factor matrices. If that sentence made sense to you, this node is for you. If it didn't, this is one of the pack's rawest entries and you'll want to skip it - SVD is deep linear algebra, and this node is the raw cv2.SVDecomp function with nothing between you and the math.

What it's actually good for: SVD is the workhorse behind solving linear systems, computing pseudo-inverses, low-rank approximation (truncate W and you get a compressed version of the matrix), and conditioning analysis - the singular values tell you how "well-behaved" a matrix is. In a ComfyUI context that means the workflow masochist doing matrix math in a graph: solving A·x = b via SVDecomp_0 + SVBackSubst_0 (the pack's companion node, which is literally the "and now solve it" step), or computing a fundamental/homography from point correspondences. You're not going to hit this by accident building a normal image pipeline - you have to go looking for it.

Inputs and output:

  • src - NPARRAY; the matrix to decompose.
  • flags - INT; the SVD flag enum. 0 is the plain default (full decomposition). The useful alternates: SVD::MODIFY_A (1) lets cv2 overwrite src as scratch space, and SVD::FULL_UV (4) forces full-size u/vt matrices instead of economy-size. For most cases, 0 is right.
  • w, u, vt - optional NPARRAY out-parameters; leave them disconnected, the outputs carry the result.

Outputs are three NPARRAYs: nparray_0 = w (singular values, as a column), nparray_1 = u, nparray_2 = vt. Wire those into SVBackSubst_0 to solve, or use w for rank/conditioning analysis.

Honest warnings. This is auto-generated and unpolished, and the author says so: "Expect dragons!". All matrices are NPARRAY hand-built in numpy - no image path, no tensor support, no friendly shape checking, and mismatched shapes throw cv2 assertions. There's no SVDecomp_1 brief to worry about - this is the one. If you're doing serious numeric work, this is fine; if you just want to enhance images, walk past it.

Install. ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

restart. Requires opencv-contrib-python, numpy, torch; the Cannot import name 'guidedFilter' from 'cv2.ximgproc' startup error signals conflicting OpenCV packages and must be sorted first.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
woptNPARRAY
uoptNPARRAY
vtoptNPARRAY

Outputs (3)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY