OpenCV magnitude_1
OpenCV magnitude_1 — gradient magnitude, the duplicate you can ignore
- x
- y
- magnitude
- nparray
magnitude_1 and magnitude_0 are the same node - the pack's auto-generator emits _0/_1 duplicates because OpenCV declares each function twice in its type stubs (regular matrices and OpenCL UMat), and it numbers the overloads instead of merging them. Same cv2.magnitude call, same two inputs, same output. There's no UMat/GPU path hiding behind the _1; the author confirmed nothing here runs on OpenCL. So: treat this as the manual for cv2.magnitude.
What it does is genuinely useful if you're building edge detection by hand. It computes sqrt(x² + y²) per pixel across two same-shape arrays - usually the X and Y Sobel gradients of an image. The result is the gradient magnitude: how fast intensity changes at every pixel, in every direction at once. A single-direction Sobel only catches edges perpendicular to it; magnitude catches them all. It's the canonical "combine the two gradients" step in a classic CV edge pipeline.
The inputs
- x - first
NPARRAY(X gradient). - y - second
NPARRAY(Y gradient), same shape asx. - magnitude - optional out-parameter in the OpenCV call-by-reference tradition. The README says avoid these; the result is on the
nparrayoutput.
Nothing to tune - there are no knobs. If both inputs are right, the output is right.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Restart, or ComfyUI Manager → "opencv". Requires opencv-contrib-python, numpy, torch.
Troubleshooting
- Dark, floaty output - gradient magnitudes live far outside 0–255 and are floats. Normalize before previewing; a raw preview looks nearly black.
- Shape mismatch -
xandymust match. If your two Sobel branches diverged (a crop, a resize), that's the bug. - Batch error -
batch_size==1only; useImageFromBatch.
The honest use-it-or-not call: if your goal is edges for ControlNet, Canny is the one-stop shop and you don't need magnitude at all. If your goal is a continuous edge-strength map - say, for a custom threshold, a line-art pass, or a depth-ish effect - this is the correct building block, and magnitude_1 is as good as magnitude_0. Just don't wire both into your graph expecting different results; you'll get the same thing twice.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| x | NPARRAY | — | |
| y | NPARRAY | — | |
| magnitudeopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |