OpenCV mulTransposed_0
XᵀX, for the rare ComfyUI workflow that needs linear algebra
- src
- dst
- delta
- nparray
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ᵀ. DefaultTrue.scale(FLOAT) - a constant multiplier on the result (1.0is neutral).dtype(INT) - output type;-1keeps the input type,6isCV_64F(float64), a safe choice for matrix math.delta(optionalNPARRAY) - subtract this fromsrcbefore multiplying (for centering).dst(optionalNPARRAY) - 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ᵀXneedssrcshaped samples×features,XXᵀfeatures×samples. deltashape mismatch - it must be broadcast-compatible withsrc.- Result looks like garbage when viewed - it's a matrix, not an image. Don't feed it to a viewer.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| aTa | BOOLEAN | — | |
| scale | FLOAT | — | |
| dtype | INT | — | |
| dstopt | NPARRAY | — | |
| deltaopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |