OpenCV transform_0
Color-grade any image with one matrix multiply
- src
- m
- dst
- nparray
cv2.transform is the node you didn't know you wanted for color work. It applies a matrix multiply to every pixel independently - and once you realize that's all a color-space conversion or a color grade is, you've got a surprisingly capable grading tool. Want to shift every pixel's channels around, apply a channel mixing matrix, or implement a rough conversion that no built-in node does? One 3×3 matrix in, everything transforms.
It's a genuinely useful node in a pack that's mostly niche math. The trick to loving it: treat m as a 3×3 matrix of weights. Each output channel becomes a weighted sum of the input channels. Zero out the red-to-blue weight and you've killed a color cast; swap entire rows and you've remapped the channel order; scale the diagonal and you've turned the gain up per channel. That's the same math OpenCV uses internally for cvtColor color-space conversions, exposed raw. The KB's post-processing essay nails the framing: deterministic pixel ops like this are the correct, millisecond tool for color fixes, versus re-rolling a generation because "the colors are off."
Inputs and outputs that matter
- src (NPARRAY) - the image (or array) to transform.
- m (NPARRAY) - the transformation matrix. For a normal 3-channel image that's a 3×3 float matrix;
mmust have as many columns as the image has channels. This is the whole node.
The optional dst is an out-parameter - leave it unwired, per the pack README's standing advice. The output is nparray, which continues the OpenCV chain or returns through Nparrays2Image to IMAGE.
One detail that trips people: this is a per-pixel transform, not a geometric warp. cv2.transform never moves pixels around; it changes their values. The geometric cousin is warpPerspective, which lives elsewhere in this pack. Wrong node, wrong result - your image just recolors instead of distorting.
Installation
The pack installs once: ComfyUI Manager (search "OpenCV"), or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, then restart. Dependency is opencv-contrib-python (pip install opencv-contrib-python). No models.
Common issues
The classic failure here is feeding m the wrong shape - if your matrix's column count doesn't match the channel count, OpenCV throws an assertion error and the node dies. Build the matrix as an nparray with the same number of columns as channels. And remember the whole pipeline runs at batch size 1 on NPARRAY: Image2Nparray in, Nparrays2Image out, ImageFromBatch if your image carries a batch.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| m | NPARRAY | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |