Nodes/opencv-comfyui/OpenCV mulTransposed_0
ComfyUI Node

OpenCV mulTransposed_0

XᵀX, for the rare ComfyUI workflow that needs linear algebra

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV mulTransposed_0
  • src
  • dst
  • delta
  • nparray
aTa
scale
dtype

mulTransposed_0 wraps cv2.mulTransposed, which computes a Gram / scatter matrix: dst = scale * (src - delta)ᵀ · (src - delta) when aTa is true, and scale * (src - delta) · (src - delta)ᵀ when it's false. That's the matrix you get when you multiply a data matrix by its own transpose - the covariance-ish object at the heart of PCA, linear regression, and a lot of statistics. It is also, honestly, one of the least image-related nodes in this pack. Let's be clear about when you'd ever touch it.

What it's for

If you lay out a dataset as a matrix where each row is a sample and each column is a feature, then XᵀX (with aTa=True) is a square matrix whose entries measure how the features co-vary - the scatter matrix, one scaling step from the covariance matrix. Feed that into eigen_0 or eigenNonSymmetric_0 (also in this pack) and you've got a PCA-style analysis.

The image connection is thin but real: think of an image as a matrix of samples. If your workflow builds a small matrix of pixel samples or feature vectors and you need its Gram matrix, this is the node. The delta input subtracts a mean vector first - set it to the dataset mean and aTa=True and you're computing the centered scatter matrix directly.

Inputs

  • src (NPARRAY) - the data matrix. Rows vs columns matter, but only in which transpose order you pick.
  • aTa (BOOLEAN) - True: XᵀX. False: XXᵀ. Default True.
  • scale (FLOAT) - a constant multiplier on the result (1.0 is neutral).
  • dtype (INT) - output type; -1 keeps the input type, 6 is CV_64F (float64), a safe choice for matrix math.
  • delta (optional NPARRAY) - subtract this from src before multiplying (for centering).
  • dst (optional NPARRAY) - the out-parameter; leave unconnected.

Output: nparray - a matrix, not an image. Do not route it into Nparrays2Image.

The honest take

This is linear algebra you almost certainly don't need inside a generation graph. If you find yourself needing a Gram matrix, you're probably doing real computation, and numpy in a Python script is a better home for it than a node chain. Where it does shine: keeping an "everything in the graph" experiment self-contained, or teaching yourself how covariance works visually. The mulTransposed_1 twin is identical - overload-derived numbering, pick _0.

Installing

Part of geroldmeisinger/opencv-comfyui. Manager → search "opencv-comfyui", or:

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

restart. Dependency: opencv-contrib-python.

Troubleshooting

  • Dimensions don't line up - check which order you're asking for; XᵀX needs src shaped samples×features, XXᵀ features×samples.
  • delta shape mismatch - it must be broadcast-compatible with src.
  • Result looks like garbage when viewed - it's a matrix, not an image. Don't feed it to a viewer.
Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
aTaBOOLEAN
scaleFLOAT
dtypeINT
dstoptNPARRAY
deltaoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY