Nodes/opencv-comfyui/OpenCV Sobel_1
ComfyUI Node

OpenCV Sobel_1

Same edge detector, second overload — use it the same way

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV Sobel_1
  • src
  • dst
  • nparray
ddepth
dx
dy
ksize
scale
delta
borderType

First, the thing that will save you the most confusion: Sobel_1 and Sobel_0 are the same node. Same inputs, same behavior, both call cv2.Sobel with identical arguments. The _1 is just the pack's auto-generator numbering the second overload it found in OpenCV's type stubs, and for Sobel the two generated nodes came out functionally identical. Pick either one; delete the other; move on.

What the node does when you actually use it: computes the first derivative of your image - the gradient - along a chosen axis. It's the classic Sobel edge detector, useful for line-art, directional detail, and edge-aware masking inside a workflow. This is deterministic pixel work, not generative: instant, cheap, and no model involved.

The inputs (identical to Sobel_0):

  • src - NPARRAY from Image2Nparray (BGR uint8). Greyscale input via cvtColor code 6 is normal for edge work.
  • dx / dy - INT, derivative order per axis. dx=1, dy=0 = horizontal-edge pass; dx=0, dy=1 = vertical-edge pass.
  • ddepth - INT, and this is the knob that trips people up. -1 keeps uint8 and clamps negative gradients to zero - you silently lose half the edge signal. 5 (CV_32F) keeps the signed values and is what you want for real gradient math.
  • ksize - INT, odd kernel size (3, 5, 7); -1 switches to the sharper Scharr kernel (only valid when dx+dy == 1).
  • scale, delta, borderType - leave at defaults.

Optional dst is the out-parameter; don't connect it. Output is one nparray, which you send to Nparrays2Image to preview or to another matrix-consuming node.

The classic beginner failure on Sobel is the depth trap: with ddepth=-1 your result looks like only half the edges survived. It's not the node - it's uint8 clamping. Set ddepth=5 and, for a viewable image, take the absolute value of the result (or combine the two directional passes into a magnitude map).

For edge maps you'll often want Canny instead - it's a complete binary edge detector and the usual first choice for lineart. Sobel's unique value is the signed gradient: it tells you not just that an edge exists but which way brightness changes across it, which matters for lighting analysis, shading reconstruction, and any pipeline that reasons about gradient direction.

Install is pack-standard: ComfyUI Manager → search "opencv-comfyui", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Needs opencv-contrib-python plus numpy/torch (already present). If startup fails with Cannot import name 'guidedFilter' from 'cv2.ximgproc', two OpenCV installs are conflicting - uninstall one.

One more note on the _0/_1 thing, since it applies pack-wide: when you see a numbered pair and both have identical signatures, the pack's README ("expect dragons") is the explanation. The generator numbers overloads without deduplicating them. For Sobel the two are interchangeable, so you only ever need one in your graph.

Categoryimage/OpenCV

Inputs (9)

NameTypeDefaultDescription
srcNPARRAY
ddepthINT
dxINT
dyINT
ksizeINT
scaleFLOAT
deltaFLOAT
borderTypeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY